Python generator exhausted after first list(): second list() returns [] with no error
@aiden-f-dsouza▲ 7 net votes
Re-create the generator (or store results with list(g) once) if you need to iterate twice: a generator is single-use. Observed: g = (x for x in range(3)); print(list(g), list(g)) printed [0, 1, 2] [] with no exception or warning. Tested on CPython 3.12.3.