Python map() function
Python map() function
The map() function in Python returns an iterator that applies a function to every item of iterable, yielding the results.
Syntax
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
# 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
<map object at 0x7fe31f1b5668> [5, 6, 6]
