Why Your Generator Expression Only Works Once (The Exhaustion Trap)
Jan 6 · 2 min read · Pop quiz. What does this print? gen = (x ** 2 for x in range(5)) print(sum(gen)) print(sum(gen)) If you said 30 and 30, you just learned something important. The actual output: 30 0 Generator Expressions Are Single-Use A generator expression with pa...
Join discussion

