Random Python dictionary key, weighted by values

This would work:

random.choice([k for k in d for x in d[k]])

Leave a Comment