In addition to itertools.chain and itertools.islice, this is possible with a number of third-party packages:

http://toolz.readthedocs.org/en/latest/api.html#itertoolz (concat, pluck, first, last, take)
https://github.com/kachayev/fn.py#streams-and-infinite-sequences-declaration (<< 'Stream' operator)
http://funcy.readthedocs.org/en/latest/seqs.html

Stdlib docs for this:

https://docs.python.org/2/howto/functional.html#iterators
https://docs.python.org/2/tutorial/classes.html#iterators
https://docs.python.org/2/library/stdtypes.html#iterator-types
https://docs.python.org/2/reference/datamodel.html#object.__iter__

On Sat, Jan 3, 2015 at 7:37 AM, yotam vaknin <tomirendo@gmail.com> wrote:
I would like to purpose that in python 3 it will be easy to chain and slice Iterators just like you can add and slice lists and tuples easily.

I think there could be 2 methods to do this:
1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by default, Resulting in  Itertool's chain(a,b) and islice(a,b,c) respectively.
2. Having itertool's chain and islice imported by default.

I think since python 3 return zip,map, dict.items and so on as iterators, it makes working with those kind of objects more difficult without having these methods around. And since those methods are important enough to have for lists, it seems important enough for iterators too.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/