Straight from the Python documentation of the itertools module:
from itertools import tee, izip
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
l = [1, 2, 3, 4, 5, 6]
for pair in pairwise(l):
print pair