def pairwise(iterable):
    """s -> (s0,s1), (s1,s2), (s2, s3), ..."""
a, b = tee(iterable)
next(b, None)
return zip(a, b)
l = [1, 2, 3, 4, 5, 6]
for pair in pairwise(l):
    pass
Collect every pair of elements from a list into tuples in Python