Which fix removes the bug?
def gen():
yield from range(3)
g = gen()
list(g)
print(list(g))
- Recreate the generator
- Convert gen to a list
- Add a return statement
- Call next() manually
A generator is exhausted after one pass, so the second list() is always empty.
Play Problem Solving ▸