selecting a random item from a set
a.schmolck at gmx.net
Mon Jan 5 17:50:59 CET 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.
More information about the Python-list