On Friday, October 12, 2012 10:22:16 AM UTC+8, Steven D'Aprano wrote:
> On Wed, 10 Oct 2012 23:44:42 -0700, suzaku wrote:
> 
> 
> 
> > I think if a programmer has used the built-in `random` module before, he
> 
> > would expect a function with "sample" in its name to return a population
> 
> > sequence.
> 
> 
> 
> I have used the random module for about fifteen years, and I still write 
> 
> random.sample when I need to use random.choice.
> 
> 
> 
> In statistics, probability, and plain English, a sample can be a single 
> 
> item: that's why we can say "a sample" or "two samples".

Thanks for sharing your experience.

As I'm not a native speaker of English, 
when I learned that `random.choice` return single item,
  and `random.sample` return a sequence of items, 
I thought that the behaviour is determined by their definitions.

> 
> 
> 
> 
> 
> > If a function is to return scalar value instead of sequence, I would
> 
> > expect it to be named "choice".
> 
> 
> 
> And I wouldn't. But what do I care? I'm never going to use the code 
> 
> you're talking about, so call it "sasquatch" if you like, it's no skin 
> 
> off my nose.
> 
> 
> 
> :)
> 
> 
> 
> 
> 
> -- 
> 
> Steven

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to