def ipeek(d):
    """Iterate through a deque, popping elements from the left after they have been seen."""
    last = None
    while d and d[-1] == '':
        d.pop()
    while d:
        yield last, d[0]
        last = d.popleft()
