Rogério Brito:
> Hi, All.
>
> I'm just getting my feet wet on Python and, just for starters, I'm coding some
> elementary number theory algorithms (yes, I know that most of them are already
> implemented as modules, but this is an exercise in learning the language
> idioms).
>
> As you can see from the code below, my background is in C, without too much
> sophistication.
>
> What I would like is to receive some criticism to my code to make it more
> Python'esque and, possibly, use the resources of the computer in a more
> efficient way (the algorithm implemented below is the Sieve of Eratosthenes):
>
my variant of the sieve
def GetPrimes(N):
arr = []
for i in range(1,N+1):
arr.append(i)
#Set first item to 0, because 1 is not a prime
arr[0]=0
#sieve processing
s=2
while s < math.sqrt(N):
if arr[s-1] != 0:
j = s*s
while j <= N:
arr[j-1] = 0
j += s
s += 1
return [x for x in arr if x != 0]
--
http://mail.python.org/mailman/listinfo/python-list