Am Thu, 17 Feb 2005 18:13:46 -0800 schrieb neutrinman: > Hi,there. How can I choose a key in dictionary randomly? > > Say, random.choice() in lists, > > or in lists: > lists = [1,2,3,4] > position = random.range(len(lists)) > word = lists[position]
Hi, try this:
import random
mydict={1: "one", 2: "two"}
print mydict[random.choice(mydict.keys())]
--
Thomas G�ttler, http://www.thomas-guettler.de/
--
http://mail.python.org/mailman/listinfo/python-list
