[Python-Dev] PEP 3142: Add a "while" clause to generator expressions

Tino Wildenhain tino at wildenhain.de
Thu Jan 22 13:37:22 CET 2009


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 yield
>> 2
>>>> g.next()
>> 3
>>>> g.next()
>> 4
>>>> g.next()
>> Traceback (most recent call last):
>>   File "<interactive input>", line 1, in <module>
>> StopIteration
>>
>> 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.
> 
>>>> from itertools import islice
>>>> g = islice((i for i in xrange(1000)), 2, 5)
>>>> list(g)
> [2, 3, 4]
> 
Yeah right, I actually believed it is already there but didn't
bother to check ;-)

Thx
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090122/81ba3427/attachment.bin>


More information about the Python-Dev mailing list