set & random.choice question

Lawrence Oluyede raims at
Wed Dec 14 21:28:36 CET 2005

Il 2005-12-14, stevecanfield at <stevecanfield at> 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 -
"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