[Tutor] when is a generator "smart?"

Danny Yoo dyoo at hashcollision.org
Sun Jun 2 06:14:58 CEST 2013


>
>
> print(list(uneven_squares(10,10000))[2:10]) #slows as y gets bigger, then
> dies
>
>
You'll want to stick with sequence operations that do not force the entire
generator's output.  In this specific case, try itertools.islice.
http://docs.python.org/2/library/itertools.html#itertools.islice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130601/7bc2c091/attachment.html>


More information about the Tutor mailing list