select random entry from dictionary

Scott David Daniels Scott.Daniels at Acm.Org
Mon Mar 7 21:32:07 EST 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