Skip to content

Instantly share code, notes, and snippets.

@porcow
Created April 13, 2012 19:39
Show Gist options
  • Select an option

  • Save porcow/2379552 to your computer and use it in GitHub Desktop.

Select an option

Save porcow/2379552 to your computer and use it in GitHub Desktop.
Prime Number Iterator
def PrimeIter(num):
seq = [ i for i in xrange(num) ]
def gen():
for n in seq:
if 2<=n<=num/2:
yield n
for s in gen():
for m in seq[s::s][1:]:
seq[m] = 0
return ( r for r in seq if r!=0 and r>=2 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment