4 ms·
http://codepad.org/MzI2fqg7 http://codepad.org/MzI2fqg7 from itertools import * primes = (i for i in count(2) if all(imap(lambda x:i%x,xrange(2,i/2)))) M
by nirmal 17y ago
http://codepad.org/MzI2fqg7 http://codepad.org/MzI2fqg7
from itertools import *
primes = (i for i in count(2) if all(imap(lambda x:i%x,xrange(2,i/2))))
My Python code for a generator expression to loop on prime numbers.
- notaddicted 17y agoyou only need to check for divisors up to sqrt(i) http://codepad.org/VMSqtLbS http://codepad.org/VMSqtLbS
- nirmal 17y agoArghh, you are right. I wonder if this will make any difference in my Project Euler problem solutions.