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(len(lists))
> > word = lists[position]
>
> Hi, try this:
>
> import random
>
> mydict={1: "one", 2: "two"}
> print mydict[random.choice(mydict.keys())]if you're going to do that, why don't you do print random.choice(mydict.values()) ? -- John Lenton ([EMAIL PROTECTED]) -- Random fortune: Quien da parte de sus cohechos, de sus tuertos hace derechos.
signature.asc
Description: Digital signature
-- http://mail.python.org/mailman/listinfo/python-list
