I note this question has already been asked here, but this mostly deals with python2: How can I multiply all items in a list together with Python?
With the demise of reduce in python3 (see What is the problem with reduce()?), what is the best way to multiply numbers in an iterable together?
eg. [1,3,7,1,2]
-> 1*3*7*1*2
I'm using something like this at the moment
def foo(list)
sum = 1
for i in list:
sum *= i
return sum
I'd really like a one liner, without having to from functools import reduce
Something like: total = sum(b for a,b in items)
but for multiplication