How about adding slice notation to iterators/generators?
Terry Reedy
tjreedy at udel.edu
Fri Oct 16 04:54:01 EDT 2009
Eloff wrote:
> I was just working with a generator for a tree that I wanted to skip
> the first result (root node.)
There is already an obvious standard way to do this.
it = <whatever>
next(it) #toss first item
for item in it:
....
>
> And it occurs to me, why do we need to do:
>
> import sys
> from itertools import islice
>
> my_iter = islice(my_iter, 1, sys.maxint)
>
> When we could simply add slice operations to generators?
>
> for x in my_iter[1:]:
> pass
1. islice works with any iterator; generator method would only work with
generators
2. iterator protocol is intentionally simple.
More information about the Python-list
mailing list