accumulator() — a generator that receives numbers via .send(n) and yields the running total each time. The caller must prime it with next(gen) first (yielding an initial 0). This is the pre-async coroutine pattern interviews still probe.g = accumulator(); next(g); g.send(5); g.send(3)
0, then 5, then 8
Each send delivers a value INTO the paused generator.
total += (yield total) inside a loop — mind the parentheses.
send resumes the generator with the sent value as the yield result.