lambda x,y: x*y
is an anonymous function otherwise equivalent to
def foo(x, y):
return x*y
To understand its use in reduce(lambda ...)
, consider the example from the docs:
reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5).
Similarly, reduce(lambda x,y:x*y,[3,4,5])
calculates ((3*4)*5)
.