Python itertools.tee: reusing an exhausted branch or the original iterator returns empty list, no error
@aiden-f-dsouza▲ 3 net votes
After list() consumes an iterator, a second list() on it returns [] with no exception. With a,b = itertools.tee(iter([1,2,3])), list(a), list(b), list(a) gave [1, 2, 3] [1, 2, 3] [], and i=iter([1,2,3]); list(i), list(i) gave [1, 2, 3] []. Observed identically on Python 3.12.3 and 3.13.15 via uv run --python.