[Tutor] primes
jfouhy at paradise.net.nz
jfouhy at paradise.net.nz
Fri Mar 18 00:48:24 CET 2005
Quoting Gregor Lingl <glingl at aon.at>:
> [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]
Heh. That's quite neat.
I can only offer one suggestion --- if you replace range with xrange, you get a
small speed improvement.
eg: On my system, it took 415 seconds to generate a list of primes < 50,000
using range, but only 386 seconds if I use the same code, but with xrange instead.
--
John.
More information about the Tutor
mailing list