0 out of 68 challenges solved

Map a function to each element in a list

Question:
Write a function called map_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 the results of applying the function to each element.

Example:
Input: map_lists(lambda x: x * 2, [1, 2, 3, 4])
Output: [2, 4, 6, 8]

def map_lists(func, lst):
    """
    Applies a function to each element in a list and returns a new list containing the results.

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

    Returns:
    list: The new list containing the results of applying the function to each element.
    """
    # TODO: Implement the map_lists function
    pass