def threes(iterator):
    """s -> (s0,s1,s2), (s1,s2,s3), (s2, s3,4), ..."""
a, b, c = itertools.tee(iterator, 3)
next(b, None)
next(c, None)
next(c, None)
return zip(a, b, c)
Iterate a list as pair (current, next) in Python