## Fix Python – Fastest way to list all primes below N

This is the best algorithm I could come up.

def get_primes(n):

numbers = set(range(n, 1, -1))

primes = []

while numbers:

p = numbers.pop()

primes.append(p)

numbers.difference_update(set(range(p*2, n+1, p)))

return primes

>>> timeit.Timer(stmt=’get_primes.get_primes(1000000)’, setup=’import get_primes’).ti….