set & random.choice question

Christophe Delord no.spam
Wed Dec 14 15:32:14 EST 2005


Hello,

On 14 Dec 2005 12:16:22 -0800, stevecanfield at yahoo.com wrote:

> I want to do something like this:
> 
>   from random import choice
>   x = set(("jenny", "jacqui", "claire", "chris", "tracy"))
>   somebody = random.choice(x)
> 
> but I bet a "TypeError: unindexable object" error. Any suggestions for
> an elegant workaround?

What about somebody = random.choice(list(x)) ?


Christophe.



More information about the Python-list mailing list