[Python-ideas] statistics module in Python3.4

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Sun Feb 2 00:24:11 CET 2014


> -----Ursprüngliche Nachricht-----
> Von: Paul Moore [mailto:p.f.moore at gmail.com]
> Gesendet: Sonntag, 2. Februar 2014 00:14
> An: Wolfgang Maier
> Cc: Python-Ideas
> Betreff: Re: [Python-ideas] statistics module in Python3.4
> 
> On 1 February 2014 22:00, Wolfgang Maier <wolfgang.maier at biologie.uni-
> freiburg.de> wrote:
> > It may also help to address this from the users' perspective. What
> > possible other use-cases could there be to pass a Mapping (let alone a
> > Counter) to one of the functions in statistics?
> 
> Why not just pass counter.elements() to the functions if you want to use a
> counter as a frequency table?
> 

The difference is that by accepting a Counter directly functions like 
statistics._sum and mode can do their job faster and more space-
efficient. Using counter.elements means exploding the data structure, 
then summing up (for _sum) all the values, while you could just sum
all key*value of the Counter.

 
> Maybe you're arguing that Mappings should be rejected with an exception?
> But that seems like an unnecessary restriction just to catch the mistaken
> usage of forgetting to call elements() on a Counter.
> 

I don't know if they should be rejected, an explicit warning in the docs that 
their treatment may be subject to change in Python3.5 may also be an 
option.

Best,
Wolfgang




More information about the Python-ideas mailing list