#
# a simple python generator
#
# a generator is like a function but uses "yield" to "return" something
# the first call to the function starts at the top and ends at yield
# each subsequent call picks up at the end of the last yield
# all function variables are static -- they maintain values between calls

# define a generator function
def fib():
  a,b=0,1
  while True:
    yield a	# the use of yield is what makes it a generator
    a,b=b,a+b

# create the generator (returns an object, does not execute function)
f=fib()		# object, not value
print(f)	# <generator object fib at 0x00000135A36EC2B0>

# use the generator in a loop
for i in range(0,10):
  x=next(f)	# next() executes the generator function
  print(x)	# values from generator function 0 1 1 2 3 5 8 13 21 34

