# iterator
x = [1, 2, "s"]
y = iter(x)
# More than will report error
print(next(y))
print(next(y))
print(next(y))
# The functions implemented by iterators , The final version is for loop
# generator : Provincial memory Fast
def a(n):
for i in range(n):
# Generator keywords
yield i * 2
d = a(3)
for i in d:
print(i)
# The generator keeps returning values , Until no
# Simplify writing :
gen = (i*2 for i in range(3))
for i in gen:
print(i)