Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Map a function over a list

Apply a function to each element of a list and return a new list of results.

Python practice16 minLists & TuplesIntermediateLast updated March 17, 2026

Problem statement

Given a list and a function that accepts a single argument, return a new list containing the result of applying the function to each element of the input list. Do not mutate the original list. The function may change the element type (e.g., int -> str).

Task

Implement map_list(lst, func) that returns a new list where each element is func(original_element).

Examples

Square numbers

Input

map_list([1, 2, 3], lambda x: x * x)

Output

[1, 4, 9]

Each element is replaced by its square.

Input format

A list (lst) and a single-argument callable (func).

Output format

A list of the same length where the i-th element is func(lst[i]).

Constraints

Do not use external libraries. Maintain order. Time complexity O(n).

Samples

Sample 1

Input

map_list(['a','b'], lambda s: s.upper())

Output

['A', 'B']

Each string is converted to uppercase.