[Tutor] primes

C Smith smichr at hotmail.com
Fri Mar 18 06:48:44 CET 2005

On Thursday, Mar 17, 2005, at 17:49 America/Chicago, 
tutor-request at python.org wrote:

> 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.
If you only calculate y up to sqrt(x) you will see a dramatic time 

import math
[x for x in xrange(2,big) if not [y for y in 
range(2,int(math.sqrt(x)+1)) if x%y==0]]


More information about the Tutor mailing list