import itertools


def prev_this_next(it):
    """
    iterator to gradually return three consecutive elements of
    another iterable. If at the beginning or the end of the iterable,
    None is returned for corresponding elements.
    """
    a, b, c = itertools.tee(it, 3)
    next(c)
    return zip(itertools.chain([None], a), b, itertools.chain(c, [None]))