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:])]
since you can be sure that l1[:-1] and l1[1:] will always be the same
length, so there is no need for a fill value (one of the enhancements you
get when using itertools.izip).
I often use zip this way when I need to get each item and its next-highest
neighbor from a list.
-- Paul
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor