Skip to content

Instantly share code, notes, and snippets.

@braingineer
Created January 14, 2016 20:42
Show Gist options
  • Save braingineer/f17fb843d4112332be51 to your computer and use it in GitHub Desktop.
Save braingineer/f17fb843d4112332be51 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
"""
Sieve of Eratosthenes (https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) using list comprehensions
"""
upper_bound = 100
noprimes = {j for i in range(2,8) for j in range(i*2, upper_bound, i)}
primes = [x for x in range(2, upper_bound) if x not in noprimes]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment