Skip to content

Instantly share code, notes, and snippets.

@codysoyland
Last active April 23, 2017 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codysoyland/7164035 to your computer and use it in GitHub Desktop.
Save codysoyland/7164035 to your computer and use it in GitHub Desktop.
A prime number generator using Python generators, inspired by concurrent prime sieve at http://play.golang.org/p/9U22NfrXeq
from itertools import count
def filter(input, prime):
for i in input:
if i % prime:
yield i
def get_primes(num):
g = count(2)
for _ in xrange(num):
prime = g.next()
yield prime
g = filter(g, prime)
for num in get_primes(10):
print num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment