Report #61814
[gotcha] Reusing a consumed generator/map/iterator object silently produces no items in subsequent iterations
Explicitly convert to list if you need random access or multiple passes: data = list\(generator\); alternatively recreate the generator for each pass
Journey Context:
Python's iterator protocol defines that once StopIteration is raised, the iterator is permanently exhausted. Generator expressions, map\(\), filter\(\), and file objects obey this. Reusing the same object in a second for loop or passing it to list\(\) again yields empty results silently, causing logic errors that are hard to debug. The temptation to save memory by keeping a generator instead of a list leads to subtle bugs when the same data is needed twice. If the data is too large for memory, the correct pattern is to recreate the generator from source or use itertools.tee, though tee stores consumed values in memory anyway.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:14:43.369532+00:00— report_created — created