The map() function applies a given function to each item of an iterable (list, tuple etc.) and returns a list of the results.
Basic Syntax :- map(func,iter)
Note :- we can provide more than one iterable in the map function.
Example :- a = [1,2,3,4,5]
c =list(map(lambda x : x+1 ,a))
print(c)
The output is [2, 3, 4, 5, 6]
Example :- More than one iterable
a = [1,2,3,4,5]
b=[1,2,3,4,5]
c =list(map(lambda x,y : x+y ,a,b))
print(c)
#The output is [2, 4, 6, 8, 10]
Basic Syntax :- map(func,iter)
Note :- we can provide more than one iterable in the map function.
Example :- a = [1,2,3,4,5]
c =list(map(lambda x : x+1 ,a))
print(c)
The output is [2, 3, 4, 5, 6]
Example :- More than one iterable
a = [1,2,3,4,5]
b=[1,2,3,4,5]
c =list(map(lambda x,y : x+y ,a,b))
print(c)
#The output is [2, 4, 6, 8, 10]
No comments:
Post a Comment