[Python-ideas] Integrate some itertools into the Python syntax

Chris Angelico rosuav at gmail.com
Mon Mar 28 12:34:09 EDT 2016


On Tue, Mar 29, 2016 at 3:29 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Iter*ables* are easy to slice (think list, tuple, range, etc.).
>
> Iter*ators* are the tricky ones.  And yes, there is no way to slice an
> iterator without changing its state.

*Some* iterables are easy to slice. Some are not. A dictionary is
perfectly iterable, but it doesn't make a lot of sense to slice it.
Are you slicing based on keys, or sequence (like paginating the dict),
or something else? That's why iterable slicing needs to be handled by
the type itself - a range knows how to produce a subrange, a list
knows how to produce a sublist.

ChrisA


More information about the Python-ideas mailing list