I want to get a running total from a list of numbers.
For demo purposes, I start with a sequential list of numbers using range
range
a = range
I would use a coroutine for this:
def runningTotal(): accum = 0 yield None while True: accum += yield accum tot = runningTotal() next(tot) running_total = [tot.send(i) for i in xrange(N)]