Python map() function
The map() function in Python returns an iterator that applies a function to every item of iterable, yielding the results.
Syntax
1 2 3 |
map(function, iterable, ...) |
Parameter
function: It is a required parameter that represents the function to execute for each item.
iterable: This parameter represents a sequence, collection, or an iterator object.
Return
This function returns an iterator that applies a function to every item of iterable, yielding the results.
Example 1
1 2 3 4 5 6 7 8 9 10 |
# Python program explaining # the map() function def Week(val): return len(val) str = map(Week, ('Monday', 'Tuesday', 'Wednesday')) print(str) #converting the map into a list print(list(str)) |
Output
1 2 3 4 |
<map object at 0x7fe31f1b5668> [5, 6, 6] |