[Python-ideas] Slicing and Chainging iterables.

Nick Coghlan ncoghlan at gmail.com
Sun Jan 4 09:01:57 CET 2015

On 4 January 2015 at 17:45, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:
> On Sat, Jan 3, 2015 at 11:23 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> 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.
> They probably should implement keys/etc. properly.
> collections.abc.[Mutable]Mapping make it easy to support views if you
> otherwise implement a dictionary-like object.

What people "should" do and what they actually do in practice often
differ wildly. In this particular case, folks migrating from Python 2
will frequently rename existing iter* methods to be the Python 3
implementations of the base methods.

It's technically a non-compliant implementation of the Python mapping
protocol, but you'll only encounter problems if you attempt to use
that container implementation with code that relies on the Python 3
view behaviour.


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

More information about the Python-ideas mailing list