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
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"
> 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
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