While looking up concise ways to calculate the product of a list, I was a little confused by this response. Here's the code in question:
reduce(lambda x,y:x*y,[3,4,5])
Can someone explain why this works? I'm familiar with using lambda expressions involving one variable (e.g. when using a custom compare function for sorting) but am confused why and how this works.
def f(x,y): return x*yand thenreduce(f, [3,4,5]). So is it really the behaviour ofreducewhich is confusing you?f(x,y)works to compute the product (why we needy). I think @unutbu has explained this well with an example from the documentation.reduce()either - artima.com/weblogs/viewpost.jsp?thread=98196