generate list of partially accumulated values

marek.rocki at marek.rocki at
Sun Sep 16 13:18:30 CEST 2007

Those methods of computing partial sums seem to be O(n^2) or worse.
What's wrong with an ordinary loop?

for i in xrange(1, len(l)):
    l[i] += l[i - 1]

And as for the list of objects:

ll = [l[i - 1].method(l[i]) for i in xrange(1, len(l))] + l[-1]

More information about the Python-list mailing list