$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #194

Which fix removes the bug?

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