generate list of partially accumulated values

cesco fd.calabrese at gmail.com
Sun Sep 16 12:21:59 CEST 2007


> l = [1, 2, 3, 4]
> [sum(l[:x+1]) for x in xrange(len(l))]

Thanks,

actually my problem is a bit more complex (I thought I could get a
solution by posting a simplified version...)

The list is composed of objects:
l = [obj1, obj2, obj3, obj4]
and I need to call a method (say method1) on each object as follow:
l1 = [obj1.method1(obj2), obj2.method1(obj3), obj3.method1(obj4),
obj4]

Is there a clean way of doing this?

Thanks again
Francesco




More information about the Python-list mailing list