set & random.choice question
Lawrence Oluyede
raims at dot.com
Wed Dec 14 15:28:36 EST 2005
Il 2005-12-14, stevecanfield at yahoo.com <stevecanfield at yahoo.com> ha scritto:
> I want to do something like this:
>
> from random import choice
> x = set(("jenny", "jacqui", "claire", "chris", "tracy"))
> somebody = random.choice(x)
import random
x = set(("jenny", "jacqui", "claire", "chris", "tracy"))
somebody = random.choice(list(x))
You must turn back it into a list, set has no notion of indexing
--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
More information about the Python-list
mailing list