find product of items in list in python by R4R Team

Example-

list is [1,2,3,4]
then product is 24


program-

#import the functools module
import functools

#take input of the list
print("Enter number in list")
n=map(int,input().split())

x=functools.reduce(lambda x,y:x*y,n)
print("product of list is :",x)


output-

Enter number in list
1 2 3 4
product of list is : 24


-In this program, we take an input of the list items, then using lambda function and reduce() function we find the product of the list.
-It take two items from the list and pass in lambda, and this process is repeat uptil list become of single length.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!