map
Apply a function to every item of an iterable.
Python 3.13
map(function, iterable, *iterables)- function
- The function called for each item; it takes as many arguments as there are iterables.Callable
- iterable
- The items to apply the function to.Iterable
- *iterables
- More objects whose items are passed to the function as the second, third and further arguments.Iterable
Return value
An iterator of results; wrap it in list() to get a list.
Examples
Doubling each number
Python 3.13
print(list(map(lambda x: x * 2, [1, 2, 3])))[2, 4, 6]
Function of two arguments
Python 3.13
print(list(map(pow, [2, 3, 4], [3, 2])))[8, 9]
Details
Results are computed only during iteration. With several iterables, map stops at the shortest one.
