set & random.choice question

stevecanfield at yahoo.com stevecanfield at yahoo.com
Wed Dec 14 15:16:22 EST 2005


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?

I'm using set because I want to know that I have a collection of unique
objects.

steve




More information about the Python-list mailing list