delay and force in Python

Fredrik Lundh fredrik at pythonware.com
Mon Jan 24 06:33:46 EST 2005


Nick Coghlan wrote:

>> How's this:
>>
>> Py> from itertools import islice
>> Py> print islice((x for x in xrange(1, 996) if x % 2 == 0), 1, 2).next()
>> 4
>
> Wouldn't it be nice if this could be spelt:
>
> print (x for x in xrange(1, 996) if x % 2 == 0)[2]

as I've always said, the sooner we can all use the itertools goodies without
even noticing, the better.

</F> 






More information about the Python-list mailing list