Created
February 11, 2021 22:07
-
-
Save md2perpe/95782d1691b0b6acabaf689659c12561 to your computer and use it in GitHub Desktop.
Prime number generator in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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