def gen_upto_mark(it, pred):
    """Produce @nlines of output of input sequence @it until and including when predicate @pred is True."""
    for el in it:
        yield el
        if pred(el):
            it.close()
