Re: set & random.choice question



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"
.



Relevant Pages

  • Re: CherryPy wiki not working
    ... > to some form of Amazon page. ... of the tunnel for most of his problems is Python" ... Prev by Date: ...
    (comp.lang.python)
  • Re: how to get select label?
    ... ps. do you really need CGIs? ... of the tunnel for most of his problems is Python" ... Prev by Date: ...
    (comp.lang.python)
  • Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
    ... From-the-far-end indexing is too useful a feature to trash. ... To index or slice a sequence from the far end, ... We propose a new style of slicing and indexing for Python ... Of course we do care about backward compatibility, and rejecting negative indexes would break way too much code. ...
    (comp.lang.python)
  • Possible improvement to slice opperations.
    ... After considering several alternatives and trying out a few ideas with a modified list object Bengt Richter posted,, I think I've found a way to make slice operation (especially far end indexing) symmetrical and more consistent. ... python programmers. ...
    (comp.lang.python)
  • Re: A question about reference in Python.
    ... This is really really really pointless code and a really really pointless ... Python is a superior dynamic programming ... self.prev = prev ... int *next; ...
    (comp.lang.python)