Skip to content

Instantly share code, notes, and snippets.

@andlima
Created October 1, 2011 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andlima/1256678 to your computer and use it in GitHub Desktop.
Save andlima/1256678 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Python
def primes(maximum):
discarded = set()
was_discarded = discarded.__contains__
discard_all = discarded.update
limit = maximum + 1
yield 2
for m in xrange(3, limit, 2):
if not was_discarded(m):
yield m
discard_all(xrange(m * 2, limit, m))
@mpereira
Copy link

mpereira commented Oct 1, 2011

How does it compare with mongodb?

@andlima
Copy link
Author

andlima commented Oct 1, 2011

Let's say this is not exactly web scale. :c)

@andlima
Copy link
Author

andlima commented Oct 1, 2011

BTW, "web scale" this: https://gist.github.com/1256699 :c)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment