68 Program to demonstrate map function in Python

Program:

'''2)map() function takes 2 arguments

i) lambda function

ii)list '''



# Python to illustrate map() with lambda()

#adding 5000 to each sal



list1=[10,20,30,40,50]

res = list(map(lambda x:(x+2),list1))

print(res)



print("\n\n")



emps=[(101,"miller",10000,"m",11,"hyd"),

      (102,"Blake",20000,"m",12,"pune"),

      (103,"sony",30000,"f",11,"hyd"),

      (104,"sita",40000,"f",12,"pune"),

      (105,"John",50000,"m",13,"hyd")]



#Task1: adding 5000 to each employee

res = list(map(lambda x:(x[2]+5000),emps))

print(res)

print("\n")


Output:

 Program to demonstrate map function in Python

Previous
Next Post »