def in_list(lst, val, key=None):
    """
    Searches for val in lst. If specified, key will be applied to each element
    in lst before comparing it to val.
    """
    if key is None:
        return val in lst

    for elem in lst:
        if key(elem) == val:
            return True

    return False