syntax enhancement

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Oct 5 21:55:51 EDT 2011


On Wed, 05 Oct 2011 13:31:41 -0500, Tim Chase wrote:

> I'm very -1 on the initial proposal with parens, but I wouldn't object
> to generators growing a method (__getitem__?) to do slices via
> itertools, something like
> 
>    gen = (a for a in iterator if test(a))
>    for thing in gen[4::2]:
>      do_something(thing)
> 
> acting something like
> 
>    gen = (a for a in iterator if test(a))
>    for thing in itertools.islice(gen, start=4, step=2):
>      do_something(thing)


The problem is that adding slicing to iterators is that it requires ALL 
iterators to support slicing, whether appropriate or not, and regardless 
of the implementation.

Just use islice. Not everything needs to be a built-in.



-- 
Steven



More information about the Python-list mailing list