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

Andrew Barnert abarnert at yahoo.com
Thu Aug 8 18:54:44 CEST 2013


On Aug 8, 2013, at 9:38, Ryan <rymg19 at gmail.com> wrote:

> I believe you can also shorten option 1 to:
> 
> data = list(data) if data is iter(data) else data

Sure, but why?
> 
> And, wouldn't option 2 change any data structure that isn't a list? Would that be problem or a benefit?

No, tuple, many third-party types, etc. are Sequences without being lists.

It would definitely change _some_ data structures into lists, with an obvious cost and no real benefit. (Unless we're planning a future C-accelerates version that does fast indexing.) But of the ones you'd be most likely to pass in, it will do the right thing (listify most iterators, leave tuples alone, etc.).

> 
> Steven D'Aprano <steve at pearwood.info> wrote:
>> 
>> On 09/08/13 00:58, Guido van Rossum wrote:
>>> --Guido van Rossum (sent from Android phone)
>>> On Aug 8, 2013 7:29 AM, "Steven D'Aprano" <steve at pearwood.info> wrote:
>>>> - one-pass algorithm for variance is deferred until Python 3.5, until
>>> then, lists are the preferred data structure (iterators will continue to
>>> work, provided they are small enough to be converted to lists).
>>> 
>>> How do you plan to distinguish between lists and iterators?
>> 
>> 
>> I haven't yet decided between these two snippets:
>> 
>> # option 1
>> if data is iter(data):
>> data = list(data)
>> 
>> 
>> # option 2
>> if not isinstance(data, collections.Sequence):
>> data = list(data)
>> 
>> 
>> although I'm currently leaning towards option 1.
> 
> -- 
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130808/7ee33999/attachment-0001.html>


More information about the Python-ideas mailing list