def generate_numbers(n):
for i in range(n):
yield i
for num in generate_numbers(5):
print(num)
numbers = [x for x in range(5)]
for num in numbers:
print(num)
def generate_numbers(n):
for i in range(n):
if i % 2 == 0:
yield i
for num in generate_numbers(5):
print(num)
def generate_pairs():
for i in range(3):
for j in range(3):
yield (i, j)
for pair in generate_pairs():
print(pair)
def generate_letters():
yield from 'abc'
def generate_numbers():
yield from range(1, 4)
for letter, number in zip(generate_letters(), generate_numbers()):
print(letter, number)