Re: how can i randomly choose keys in dictionary

2005-02-18 Thread John Lenton
On Fri, Feb 18, 2005 at 09:35:30AM +0100, Thomas Guettler wrote: > 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(l

Re: how can i randomly choose keys in dictionary

2005-02-18 Thread Thomas Guettler
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"

RE: how can i randomly choose keys in dictionary

2005-02-17 Thread Tony Meyer
> Hi,there. How can I choose a key in dictionary randomly? > > Say, random.choice() in lists, A dictionary's keys() are a list, so you already have the answer: >>> import random >>> d = {'a': 1, 'b': 2, 'c': 3} >>> random.choice(d.keys()) =Tony.Meyer -- http://mail.python.org/mailman/listinfo

how can i randomly choose keys in dictionary

2005-02-17 Thread 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] -- http://mail.python.org/mailman/listinfo/python-list