Skip to content

Instantly share code, notes, and snippets.

@Isweet
Created November 17, 2014 23:43
Show Gist options
  • Save Isweet/d458b6d00cbf564d56c0 to your computer and use it in GitHub Desktop.
Save Isweet/d458b6d00cbf564d56c0 to your computer and use it in GitHub Desktop.
Generate an arbitrary number of primes
import itertools
def prime_gen():
yield 2
curr = 3
seen = [2]
while (True):
yield curr
seen.append(curr)
curr = next((x for x in itertools.count(curr + 2, 2) if all(x % i != 0 for i in seen)), None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment