def butlast(coll):
    """
    Return a generator of all but the last item in ``coll``, in linear time.
    """
    first = True
    last_e = None
    for e in coll:
        if first:
            last_e = e
            first = False
            continue
        yield last_e
        last_e = e
