[Python-ideas] Slicing and Chainging iterables.

Nick Coghlan ncoghlan at gmail.com
Sun Jan 4 08:23:08 CET 2015


On 4 January 2015 at 07:14, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> But it would be a pretty major change to
> Python to move from iterators to views. And iterators are much simpler to create than views, so the tradeoff probably wouldn't be worth it, even if it weren't for the historical/compatibility issue. (It's much the same with Haskell-style lazy lists; Python iterables can only substitute for lazy lists 90% of the time, but that doesn't mean lazy lists are a better language choice.)

It's worth noting that many types implement
Mapping.(keys,values,items) as iterators in Python 3 rather than as
views, and generally don't receive any complaints from users.
Iterators are very simple to implement, cover 90% of the use cases,
and in those cases where they don't, you can usually write a custom
wrapper around the original containers with view-like behaviour.

Providing an operator based spelling for itertools.chain,
itertools.islice and itertools.repeat is tempting enough on the
surface to be suggested every few years (e.g. [1]), but it creates so
many new complications on the *implementation* side that the benefits
just aren't worth the cost in additional complexity.

Cheers,
Nick.

[1] https://mail.python.org/pipermail/python-ideas/2010-April/006983.html

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list