Map Function
Multiple Choice Medium
Question
What does list(map(str, [1, 2, 3])) return?
Hint
map applies a function to each element.
Explanation
list(map(str, [1, 2, 3])) returns ["1", "2", "3"]. map applies the str function to each element, converting numbers to strings. map is lazy (returns an iterator), so list() is needed. In modern Python, list comprehensions [str(x) for x in [1,2,3]] are often preferred for readability. map is useful with predefined functions.
Related Resources
Related Lessons
- Functions
Learn Python functions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.