In [1]:
#https://dbader.org/blog/python-generators

In [19]:
def repeat_n_times(value,max_rep):
    for i in range(max_rep):
        yield value + str(i)

In [20]:
for a in repeat_n_times('hello',10):
    print(a)


hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9

In [1]:
#Hard coding
def repeat_three_times(value):
    yield value
    yield value
    yield value

In [4]:
for i in repeat_three_times("hi"):
    print(i)


hi
hi
hi

In [11]:
iterator=repeat_three_times("hello")
print(next(iterator))
print(next(iterator))
print(next(iterator))
print(next(iterator))


hello
hello
hello
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-11-248231920c34> in <module>()
      3 print(next(iterator))
      4 print(next(iterator))
----> 5 print(next(iterator))

StopIteration: 

In [ ]: