select random entry from dictionary

Scott David Daniels Scott.Daniels at Acm.Org
Tue Mar 8 03:32:07 CET 2005


Tony Meyer wrote:
>>How can I select a random entry from a dictionary, regardless of its 
>>key-values?
> 
>>>>a = random.choice(d.keys())
>>>>a, d[a]

Or even:
    key, value = random.choice(d.items())

or:
    value = random.choice(d.values())


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list