Chapters
Python114 chapters

ReferenceBuilt-in functions

map()

Applies a function to every item.

Signature

map(function, iterable)

Parameters

NameMeans
functioncalled once per item
iterableone or more sequences

Returns

An iterator, used up after one pass.

Example

Python
print(list(map(str.upper, ["a", "b"])))
print(list(map(lambda n: n * n, [1, 2, 3])))
print(list(map(int, ["1", "2"])))

Output

['A', 'B']
[1, 4, 9]
[1, 2]

See also