Python map() function is an inbuilt function that takes a lambda function and applies that function to all the elements of specified iterable and returns map objects. The map is often used with a lambda function.
Read: Python Lambda Function
Python example map lambda function
Simple example code map function using lambda in Python. Get the square of the given list.
nums1 = [1, 2, 3, 4, 5] sq = list(map(lambda a: a * a, nums1)) print(sq)
The map() can accept more than one iterable. Using two lists and adding their values.
list1 = [1, 2, 3, 4, 5] list2 = [6, 7, 8, 9, 10] square_numbers = list(map(lambda x, y: x + y, list1, list2)) print(square_numbers)
Output: [7, 9, 11, 13, 15]
Do comment if you have any doubts and suggestions on this Python lambda tutorial.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.