Skip to content

Instantly share code, notes, and snippets.

@toshsan
Created July 21, 2014 19:29
Show Gist options
  • Save toshsan/2ff6a17c185e313c8a41 to your computer and use it in GitHub Desktop.
Save toshsan/2ff6a17c185e313c8a41 to your computer and use it in GitHub Desktop.
Python generator for N Prime number
def primes(n):
yield 2
primes=[2]
x = 1
i = 3
while(x<n):
isprime=True
for p in primes:
if i%p==0: isprime = False
if isprime:
primes.append(i)
yield i
x +=1
i +=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment