cesco пишет: > Hi, > > I have the following list: > l = [1, 2, 3, 4] > and I'd like to obtain a list like the following: > l_partial_sum = [1, 3, 6, 10] (that is [1, 1+2, 1+2+3, 1+2+3+4])
>>> def iscan(f, seq, acc=0): ... for i in seq: ... acc = f(acc,i) ... yield acc ... >>> list(iscan(operator.add, xrange(1,5))) [1, 3, 6, 10] >>> -- http://mail.python.org/mailman/listinfo/python-list