selecting a random item from a set

Alexander Schmolck a.schmolck at gmx.net
Mon Jan 5 11:50:59 EST 2004


Jp Calderone <exarkun at intarweb.us> writes:

> > choice(dict(1:"gets this", 2:"gets that", "three":"gets the key"))
> > 
> 
>   This is as broken in the current choice implementation as in the one I
> proposed.  I don't think it makes any difference to the question at hand.

The current implementation will always return values and complain if it
unsuccesfully tries a value between 0 and len(dict). I'd argue this is very
much preferable to always "succeeding" and sometimes returning a key and
sometimes returning a value.

'as




More information about the Python-list mailing list