On Wed, Apr 13, 2016 at 12:45 PM Guido van Rossum <guido@python.org> wrote:
On Wed, Apr 13, 2016 at 2:47 AM, Rob Cliffe <rob.cliffe@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.
Repeated random sampling from the same population is a common use case ("bootstrapping"). Perhaps the oversight was *allowing* sets as input into random.sample.