from itertools import * primes = (i for i in count(2) if all(imap(lambda x:i%x,xrange(2,i/2))))
http://codepad.org/VMSqtLbS