Generator pattern are incredibly important and useful pattern in python. It actually creates an iterator.
Reference code is:
#this is a general function
def isprime(n);
if n == 1:
return False
for x in range(2,n):
if n % x == 0;
return False
else:
return True
# this is a generator function
def primes(n = 1):
while(True):
if isprime(n): yield n
n += 1