best cumulative sum

Robert Kern robert.kern at gmail.com
Sun Nov 20 23:24:52 EST 2005


David Isaac wrote:
> 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?

Define better. More accurate? Less code?

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