python calculates an instance of the product of all elements in a list

  • 2021-06-28 12:59:18
  • OfStack

As follows:


#  seek 1 Product of all elements in list 

from functools import reduce

lt = [1,2,3,4,5]

ln = reduce(lambda x,y:x * y,lt)

print(ln)

Related articles: