def iter_with_last_flag(iterable):
    """Iterate over an iterable and yield a 2-tuple containing the current item and a Boolean
    indicating if it is the last item.

    """
    last_index = len(iterable) - 1
    for i, x in enumerate(iterable):
        yield x, i == last_index
