Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created February 11, 2021 22:07
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 md2perpe/95782d1691b0b6acabaf689659c12561 to your computer and use it in GitHub Desktop.
Save md2perpe/95782d1691b0b6acabaf689659c12561 to your computer and use it in GitHub Desktop.
Prime number generator in Python
import itertools
def primes():
def sieve(numbers):
try:
n = next(numbers)
yield n
yield from sieve(filter(lambda m: m%n!=0, numbers))
except StopIteration:
return
return sift(itertools.count(2))
first_hundred_primes = list(itertools.islice(primes(), 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment