Re: best cumulative sum



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@xxxxxxxxx

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

.



Relevant Pages

  • Re: best cumulative sum
    ... Erik Max Francis wrote: ... > Micah Elliott wrote: ... >> On Nov 21, David Isaac wrote: ... >>> What's the good way to produce a cumulative sum? ...
    (comp.lang.python)
  • Re: best cumulative sum
    ... David Isaac wrote: ... > What's the good way to produce a cumulative sum? ... -- Richard Harter ... Prev by Date: ...
    (comp.lang.python)