Lambda with reduce() Function in Python

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

# Program for reduce function 
import functools
# def myfunction(a,b):
#       return a+b

# mylist=[2,4,6,8]
# add=functools.reduce(myfunction,mylist)
# print(add)



#Reduce with Lamda function

mylist=[2,4,6,8,6,7,8,12,55]
value=functools.reduce(lambda a,b:(a+b),mylist)
print(value)

mylist=[2,3,4,5,6,8]
mylist1=list(map(lambda x:(x*x),mylist))

print(mylist1)

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *