Slide window.

def window(seq, count=2):
    """Slide window."""
    iseq = iter(seq)
    result = tuple(islice(iseq, count))
    if len(result) == count:
        yield result
    for elem in iseq:
        result = result[1:] + (elem,)
        yield result