Skip to content

Instantly share code, notes, and snippets.

@braingineer
braingineer / sieve.py
Created January 14, 2016 20:42
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]