I want to calculate the product sum of two lists using reduce() and a regular function.
The regular function to return the product is defined as:
def func(maturity, weight):
return maturity * weight
reduce(func, zip(terms, weights))
"TypeError: can't multiply sequence by non-int of type 'tuple'"
I think you're mis-understanding the use of
reduce. What it does is apply an operation repeatedly on a vector to produce a scalar as the end result. What you want to do is apply the same function on separate elements which are not related. For that purpose, you need
out = map(func, terms, weights)
As Jon Clements noted, if your function is as simple as element-wise multiplication, you might consider using
import operator out = map(operator.mul, terms, weights)