I am trying to write a program in python to generate prime numbers using logic similar to the one used in writing the prime number program in Haskell(the one that is found at the top of their website). I have written the following two generator functions.
def integers():
i=2
while True:
yield i
i+=1
def primes(li):
x=li
while True:
i=next(x)
y=(j for j in x if %i!=0)
yield i
x=y
Integers is a generator of the numbers 2,3,4,5... So my guess was
a=primes(integers())
should give a generator for the prime numbers but it gives nothing of the sort. This is the output I am getting.
>>> next(a)
2
>>> next(a)
3
>>> next(a)
4
>>> next(a)
5
>>> next(a)
6
Any suggestions?