def takewhile(pred, *args):
    """Produce a sequence with the same elements as the input sequence
    until pred returns false for some element; that element and all
    those following are discarded.  The filter predicate is passed an
    element of the input sequence plus extra arguments, if provided.
    """
    def taker(input):
        for elt in input:
            if pred(elt, *args):
                yield elt
            else:
                break

    return taker