Lesson guide
What this Python exercise practices
Map a function over a list is a intermediate practice lesson that focuses on lists, iteration, filtering. It is designed to be solved in about 16 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- List values
- Basic indexing
Difficulty and time
- Level
- Intermediate
- Estimated time
- 16 minutes
Practice path
Summary
Apply a function to each element of a list and return a new list of results.
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]
Explanation
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 input 0
map_list(['a','b'], lambda s: s.upper())
Sample output 0
['A', 'B']
Explanation 0
Each string is converted to uppercase.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.