def takewhile(pred, lst):
    """Iterate over `lst` until `pred` is True and return only the iterated
    elements."""
    r = []
    for e in lst:
        if pred(e) == False:
            break
        r.append(e)
    return r
