Re: set & random.choice question
- From: Lawrence Oluyede <raims@xxxxxxx>
- Date: Wed, 14 Dec 2005 21:28:36 +0100
Il 2005-12-14, stevecanfield@xxxxxxxxx <stevecanfield@xxxxxxxxx> 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"
.
- Follow-Ups:
- Re: set & random.choice question
- From: cgriddell
- Re: set & random.choice question
- References:
- set & random.choice question
- From: stevecanfield
- set & random.choice question
- Prev by Date: Re: Newbie needs help with regex strings
- Next by Date: Re: Difference between ActivePython and Python.org
- Previous by thread: set & random.choice question
- Next by thread: Re: set & random.choice question
- Index(es):
Relevant Pages
|