Re: [Tutor] Help Optimise Code

2008-12-04 Thread Kent Johnson
On Thu, Dec 4, 2008 at 11:38 AM, Jörg Wölke <[EMAIL PROTECTED]> wrote: > #!/usr/bin/env python > > l=1*[1] > for i in range(2,len(l)): >if l[i] == 1: > print i > for j in range(i+1,len(l)): > if j%i == 0: for j in range(2*i, len(l), i): would be much faster

Re: [Tutor] Help Optimise Code

2008-12-04 Thread J�rg W�lke
* Richard Lovely <[EMAIL PROTECTED]> [081123 11:35]: > I've tried a the sieve of erath-whatever as in test_generator, > implemented using itertools functions, but it hit max recusion depth > somewhere before 1000 primes, and I'm after millions of primes. I found an old implementation for some exer

Re: [Tutor] Help Optimise Code

2008-11-21 Thread Kent Johnson
On Wed, Nov 19, 2008 at 8:13 AM, Richard Lovely <[EMAIL PROTECTED]> wrote: > Please don't suggest changing languages. I like python. Although if > you want to write an extension for me, and provide the source and a > makefile, please feel free. I have a MinGW install that's doing > nothing. (Just

Re: [Tutor] Help Optimise Code

2008-11-21 Thread Rich Lovely
On a small side note, the docs say array.array is supposed to be efficient. Testing has shown in this function, a list is faster (at least for x<10). A set is faster still - at least over the same range on my computer,, but you can't guarantee ordering, which makes it inconsistent - an

Re: [Tutor] Help Optimise Code

2008-11-19 Thread Lie Ryan
On Wed, 19 Nov 2008 13:13:18 +, Richard Lovely 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. This is what I've got so > far: > > Code: Select all > import math, array > > def count2(start_at=0): >

Re: [Tutor] Help Optimise Code

2008-11-19 Thread Kent Johnson
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

[Tutor] Help Optimise Code

2008-11-19 Thread Richard Lovely
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. This is what I've got so far: Code: Select all import math, array def count2(start_at=0): 'Yield every third integer, beginning with start_at' # this has been tes