generate list of partially accumulated values

marek.rocki at wp.pl marek.rocki at wp.pl
Sun Sep 16 07:18:30 EDT 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