On Wed, Jun 17, 2009 at 7:11 PM, Robert Berman <berma...@cfl.rr.com> wrote:
> Emille, > > Thank you for the example of list splicing. Do you know if this is faster > than a more conventional loop statement as in my code for primearray which > is in my original post (reprinted here) > > The code is as follows: > > def BuildSieve(itemsin): > TheSieve=list() > TheSieve = range(0,itemsin+1) > TheSieve[1]=0 > for i in range(2,itemsin+1): > if (TheSieve[i] > 0): > j = i + i > while (j <= itemsin): > TheSieve[j] = 0 > j+=i > return TheSieve > > It is called with PrimaryList = BuildSieve(1000000) > I'm curious if it wouldn't be faster to use xrange. I know for certain instead of range(0, itemsin+1) you could use TheSieve = [1, 2] TheSieve.extend(range(3, itemsin+1,2)) Which would save you at least half the time in your generation. Since your first step should be removing multiples of two, that should be a big help. HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor