next until the generator raises StopIteration.
g = (c for c in "ab")
got = []
while True:
try:
got.append(next(g).upper())
except StopIteration:
break
print(got, next(g, "end"))
What does the program print?Log in to join the discussion.
Loading…