generator slides review

andrea crotti andrea.crotti.0 at gmail.com
Sun Feb 2 05:48:40 EST 2014


2014-02-01 Miki Tebeka <miki.tebeka at gmail.com>:
>
> My 2 cents:
>
> slide 4:
> [i*2 for i in range(10)]
>

Well this is not correct in theory because the end should be the max
number, not the number of elements.
So it should be
[i*2 for i in range(10/2)] which might be fine but it's not really
more clear imho..

> slide 9:
> while True:
>     try:
>         it = next(g)
>         body(it)
>     except StopIteration:
>         break
>

Changed it thanks

> slide 21:
> from itertools import count, ifilterfalse
>
> def divided_by(p):
>     return lambda n: n % p == 0
>
> def primes():
>     nums = count(2)
>     while True:
>         p = next(nums)
>         yield p
>         nums = ifilterfalse(divided_by(p), nums)
>

Thank you that's nicer, but ifiilterfalse is not in Python 3 (could
use filter of course).



More information about the Python-list mailing list