map()

A built-in that applies a function to every item of one or more iterables and returns a lazy iterator.

In more detail

map(f, items) produces f(item) for each item only when asked, so list() is needed to see all the results at once. With several iterables, f receives one item from each and map stops at the shortest. Like every iterator, a map object is used up after one pass.

Example

m = map(lambda x: x * 10, [1, 2])
print(list(m), list(m))   # [10, 20] []

Related terms

Taught in

References

Certification courses