The map() function in Python is a function that applies a given function to all the iterables and returns a new list.
SYNTAX:
map(function, iterable)
Let’s take an example to demonstrate the use of the lambda functions within the map() function:
EXAMPLE:
1
2
3 |
my_list = [2,3,4,5,6,7,8]
new_list = list(map(lambda a: (a/3 != 2), li))
print(new_list) |
OUTPUT:
[True, True, True, True, False, True, True]
The above output shows that, whenever the value of the iterables is not equal to 2 when divided by 3, the result returned should be True. Hence, for all elements in my_list, it returns true except for the value 6 when the condition changes to False.