generator slides review

Miki Tebeka miki.tebeka at gmail.com
Sat Feb 1 17:50:48 CET 2014


On Saturday, February 1, 2014 6:12:28 AM UTC-8, andrea crotti wrote:
> I'm giving a talk tomorrow @Fosdem about generators/iterators/iterables..
> 
> 
> 
> The slides are here (forgive the strange Chinese characters):
> 
> https://dl.dropboxusercontent.com/u/3183120/talks/generators/index.html#3
> 
> 
> 
> and the code I'm using is:
> 
> https://github.com/AndreaCrotti/generators/blob/master/code/generators.py
> 
> and the tests:
> 
> https://github.com/AndreaCrotti/generators/blob/master/code/test_generators.py
> 
> 
> 
> If anyone has any feedback or want to point out I'm saying something
> 
> stupid I'd love to hear it before tomorrow (or also later I might give
> 
> this talk again).
> 
> Thanks

My 2 cents:

slide 4:
[i*2 for i in range(10)]

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

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)



Another resource you can point to is http://www.dabeaz.com/generators/

Good luck.



More information about the Python-list mailing list