Below is a python program I found to find prime numbers using Sieve of Eratosthenes. It uses filter and generator. I\'m not able to understand it.
def _odd_i
First, filter over iterator returns another iterator. I.e. when we do something like:
it = filter(_not_divisible(3), it)
it = filter(_not_divisible(5), it)
We get a chained iterator "odd number AND not divisible by 3 AND not divisible by 5". It is somewhat similar to chained decorators, where we get an equivalent of:
# assuming we have decorator @not divisible
@not_divisible(2)
def iter():
return xrange(inf)
# then, at every subsequent prime we do something like:
iter = not_divisible(3)(iter)
# next prime is 5:
iter = not_divisible(5)(iter)
... and so on