def filter_list(input_list, key_fn=(lambda x: x), filter_keys=None):
    """Filter a list with a list of keys

    Args:
        input_list: list to be filtered
        key_fn: a function to generate keys from elements in the list
        filter_keys: keys to intersect with

    Returns:
        filtered_input_list: filtered list
    """
    if filter_keys is None:
        filtered_input_list = input_list
    else:
        input_dict = {key_fn(x): x for x in input_list}
        keys = set(input_dict.keys()) & set(filter_keys)
        keys = sorted(list(keys))
        filtered_input_list = [input_dict[key] for key in keys]
    return filtered_input_list