[Python-Dev] PEP 3142: Add a "while" clause to generator expressions
catch-all at masklinn.net
Thu Jan 22 14:44:41 CET 2009
On 22 Jan 2009, at 12:42 , Nick Coghlan wrote:
> Tino Wildenhain wrote:
>>>> g=(i for i in xrange(1000))[2:5]
>>>> g.next() # wrapper would now step 2 times w/o yield and 1 with
>> Traceback (most recent call last):
>> File "<interactive input>", line 1, in <module>
>> as expected - this could be included into itertools for now.
> Slicing of arbitrary iterators has been supported by itertools ever
> since the module was first added to the standard library.
islice is pretty annoying in some aspects, though. Mainly because it
doesn't accept kwargs and defaults to requiring the stop argument. So
drop(iterable, n) has to be written islice(iterable, n, None) (and of
course the naming isn't ideal), and you can't really use
functools.partial since the iterator is the first argument (unless
there's a way to partially apply only the tail args without kwargs).
More information about the Python-Dev