def intervals(seq):
    """Iterate over each successive pair in a sequence.

    Examples
    --------
    >>> for i in intervals([1, 2, 3, 45]):
    ...     print(i)
    ...
    (1, 2)
    (2, 3)
    (3, 45)
    """
    iterator = iter(seq)
    try:
        last = next(iterator)
    except StopIteration:
        return
    for item in iterator:
        yield last, item
        last = item
