best cumulative sum

David Isaac aisaac0 at verizon.net
Sun Nov 20 23:13:57 EST 2005


What's the good way to produce a cumulative sum?
E.g., given the list x,
cumx = x[:]
for i in range(1,len(x)):
 cumx[i] = cumx[i]+cumx[i-1]

What's the better way?

Thanks,
Alan Isaac





More information about the Python-list mailing list