def pairwise_circle(iterable):
    """s -> (s0,s1), (s1,s2), (s2, s3), ... (s<last>,s0)"""
a, b = itertools.tee(iterable)
first_value = next(b, None)
return itertools.zip_longest(a, b, fillvalue=first_value)
Попарный круговой цикл Python for