On Wed, Nov 19, 2008 at 8:13 AM, Richard Lovely <[EMAIL PROTECTED]> wrote: > I'm pretty new to code optimisation, so I thought I'd ask you all for advice. > > I'm making an iterative prime number generator.
You might be interested in this recipe and discussion: http://code.activestate.com/recipes/366178/ According to Wikipedia, the siev of Atkin is faster than sieve of Eratosthenes: http://en.wikipedia.org/wiki/Sieve_of_Atkin > This is what I've got so far: > test = (not x % p) and -1 or p > sqrtX > if test == -1: # (not x % p) == true > break > elif test: # (p > sqrtX) == true > yield x > knownPrimes.append(x) > break You are duplicating your tests, why not if (not x % p): break elif p > sqrtX: ... ? Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor