test
view primes.py @ 0:853dcd4de2a6
a
author | test |
---|---|
date | Thu Jan 01 00:00:00 1970 +0000 (1970-01-01) |
parents | |
children |
line source
1 #!/usr/bin/env python
3 """Fun with generators. Corresponding Haskell implementation:
5 primes = 2 : sieve [3, 5..]
6 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
7 """
12 """Generate all primes."""
15 # It is important to yield *here* in order to stop the
16 # infinite recursion.