From itertools cookbook. [a, b, c, ...] -> (a, b), (b, c), ...

def pairwise(iterable):
    """From itertools cookbook. [a, b, c, ...] -> (a, b), (b, c), ..."""
    first, second = tee(iterable)
    next(second, None)
    return zip(first, second)