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

Andrew Barnert abarnert at yahoo.com
Tue Mar 22 16:11:52 EDT 2016


On Mar 22, 2016, at 12:52, Koos Zevenhoven <k7hoven at gmail.com> wrote:
> 
> One thought that comes to mind is to add some stuff from itertools as
> attributes of iter. For example: iter.slice(...). Kind of like a
> factory method, although iter is not really a type.

The one thing from itertools that I think people most miss out on by not knowing itertools is chain.from_iterable, with chain itself a close second. Would calling them iter.chain.from_iterable and iter.chain help? I'm not sure. Other people have proposed promoting one or both to builtins (maybe named flatten and chain, respectively), but that hasn't gone over very well. Making them "class methods" of iter seems a lot less disruptive.

The other thing that I think might help is a way of writing "slice literals" more easily. Just having islice easier to find doesn't help much, because the main hurdle in writing and reading the code seems to be translating between the natural slice syntax and islice's (range-ish) unpythonic signature. Maybe islice(it, slice[:10000])? Or even islice(it)[:10000]?




More information about the Python-ideas mailing list