[Python-ideas] Pre-PEP: adding a statistics module to Python

Andrew Barnert abarnert at yahoo.com
Wed Aug 7 00:14:15 CEST 2013


On Aug 6, 2013, at 12:44, Michele Lacchia <michelelacchia at gmail.com> wrote:
> Yes but then you lose all the advantages of iterators. What's the point in that?
> Furthermore it's not guaranteed that you can always converting an iterator into a list. As it has already been said, you could run out of memory, for instance.
> 
And the places where the stdlib/builtins do that automatic conversion--even when it's well motivated and almost always harmless once you think about it, like str.join--are surprising to most people. (Following up on str.join as an example, just about every question whose answer is str.join([...]) ends up with someone suggesting a genexpr instead of a listcomp, someone else explaining that it doesn't actually save any memory in that case, just wastes a bit of time, then some back and forth until everyone finally gets it.)

The question is whether it would be even _more_ surprising to return an error, or a less accurate result. I don't know the answer to that.

> Il giorno 06/ago/2013 18:37, "Ryan" <rymg19 at gmail.com> ha scritto:
>> That could easily be fixed:
>> 
>> variance(list(iter(data)))
>> 
>> It could take place on the inside.
>> 
>> Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>> 
>> >On 2 August 2013 18:45, Steven D'Aprano <steve at pearwood.info> wrote:
>> >> I have raised an issue on the tracker to add a statistics module to
>> >Python's
>> >> standard library:
>> >>
>> >> http://bugs.python.org/issue18606
>> >>
>> >> and have been asked to write a PEP. Attached is my draft PEP.
>> >Feedback is
>> >> requested, thanks in advance.
>> >
>> >I have another query/suggestion for the statistics module.
>> >
>> >Taking the example from the PEP:
>> >
>> >>>> from statistics import *
>> >>>> data = [1, 2, 4, 5, 8]
>> >>>> data = [x+1e12 for x in data]
>> >>>> variance(data)
>> >7.5
>> >
>> >However:
>> >
>> >>>> variance(iter(data))
>> >7.4999542236328125
>> >
>> >Okay so that's a small difference and it's unlikely to upset many
>> >people. But being something of a numerical obsessive I do often get
>> >upset about things like this. It's not that I mind the size of the
>> >error but rather that I dislike having the calculation implicitly
>> >changed. I want to think that it doesn't matter whether I pass an
>> >iterator or a list because either I get an error or I get the same
>> >result.
>> >
>> 
>> 
>> >
>> >
>> >Oscar
>> >_______________________________________________
>> >Python-ideas mailing list
>> >Python-ideas at python.org
>> >http://mail.python.org/mailman/listinfo/python-ideas
>> 
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130806/ace61386/attachment.html>


More information about the Python-ideas mailing list