Python map() Function
Python map()function is used to apply with the help of another function on all elements of specified iterable and return map object. We can also convert map abject into list, tuple etc.
Some Examples of Python map() Function
Example 1
def my_func(a):
return len(a)
x = map(my_func, ('volvo', 'honda', 'tata'))
print(x)
print(list(x)) #convert the map into a list
Output of the above program is
Example 2
def my_func(a, b):
return a + b
x = map(my_func, ('lemon', 'banana', 'avocado'), ('orange', 'mango', 'pineapple'))
print(x)
print(list(x)) #convert the map into a list
Output of the above program is
Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments |
---|
No Content Found. |
Interview Questions & Answers |
---|
No Content Found. |