[Python-ideas] random.choice on non-sequence

Guido van Rossum guido at python.org
Wed Apr 13 12:31:05 EDT 2016


On Wed, Apr 13, 2016 at 2:47 AM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
> Isn't there an inconsistency that random.sample caters to a set by
> converting it to a tuple, but random.choice doesn't?

Perhaps because the use cases are different? Over the years I've
learned that inconsistencies aren't always signs of sloppy thinking --
they may actually point to deep issues that aren't apparently on the
surface.

I imagine the typical use case for sample() to be something that
samples the population once and then does something to the sample; the
next time sample() is called the population is probably different
(e.g. the next lottery has a different set of players).

But I imagine a fairly common use case for choice() to be choosing
from the same population over and over, and that's exactly the case
where the copying implementation you're proposing would be a small
disaster.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list