Paul McGuire wrote:
Even simpler than Rich Lovely's:
newlist = [a+b for a,b in itertools.izip(l1[:-1], l1[1:])]
is to just use the built-in zip:
newlist = [a+b for a,b in zip(l1[:-1], l1[1:])]
And then there's good old reduce which sadly is going to be harder to
access in Python 3:
v = [1,2,3,4]
m = []
reduce(lambda x,y,m=m: (m.append(x+y), y)[1], v)
print m # [3, 5, 7]
--
Bob Gailer
Chapel Hill NC
919-636-4239
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor