Why Your Generator Expression Only Works Once (The Exhaustion Trap)
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...
samuelochaba.hashnode.dev2 min read