def islast(iterable):
    """
    An iterator similar to the builtin :py:func:`enumerate`, except that
    instead of the index, it returns a boolean flag indicating if the
    current element is the last one.

    Based on the recipe at http://stackoverflow.com/a/2429118/2988730.
    Saw http://stackoverflow.com/a/2429260/2988730 after writing this.
    """
    iterable = iter(iterable)
    item = next(iterable)
    for peek in iterable:
        yield False, item
        item = peek
    yield True, item
