0 out of 68 challenges solved

Filter a list using the given function

Question:
Write a function called filter_lists that takes a function and a list as input and applies the function to each element in the list. The function should return a new list containing only the elements for which the function returns True.

Example:
Input: filter_lists(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6])
Output: [2, 4, 6]

def filter_lists(func, lst):
    """
    Applies a function to each element in a list and returns a new list containing only the elements for which the function returns True.

    Args:
    func (function): The function to apply to each element.
    lst (list): The input list.

    Returns:
    list: The new list containing the filtered elements.
    """
    # TODO: Implement the filter_lists function
    pass