generate list of partially accumulated values
ZeD
vito.detullio at gmail.com
Sun Sep 16 07:16:59 EDT 2007
cesco wrote:
> 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]
to me it sounds a bit different from the original request, but...
> Is there a clean way of doing this?
l = [obj1, obj2, obj3, obj4]
l1 = [a.method1(b) for a,b in zip(l, l[1:)] + l[-1:]
--
Under construction
More information about the Python-list
mailing list