best cumulative sum

Robert Kern robert.kern at gmail.com
Mon Nov 21 01:24:21 EST 2005


Erik Max Francis wrote:
> Micah Elliott wrote:
> 
>>On Nov 21, David Isaac wrote:
>>>What's the good way to produce a cumulative sum?
>>
>>>>>import operator
>>>>>x = 1,2,3
>>>>>reduce(operator.add, x)
>>
>>6
> 
> Or just sum(x).

That just gives you the tail end. The OP asked for a cumulative sum;
that is, a list with all of the intermediate sums, too.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Python-list mailing list