def iterate_in_pairs(it, fill=0):
    """ return consecutive pairs from an iterator
    
    For instance, `list(pair_iterator('ABCDE', fill='Z'))` returns 
    `[('A', 'B'), ('C', 'D'), ('E', 'Z')]`
    
    Args:
        it (iterator): The iterator
        fill: The value returned for the second part of the last returned tuple
            if the length of the iterator is odd
            
    Returns:
        This is a generator function that yields pairs of items of the iterator
    """
    it = iter(it)
    while True:
        try:
            first = next(it)
        except StopIteration:
            break
        try:
            yield first, next(it)
        except StopIteration:
            yield first, fill
            break
