reduce(lambda x,y: (x+y)/2.0, numlist)
Why wouldn't this work? reduce(lambda x,y: (x+y)/2.0, numlist)
Why wouldn't this work?The mean is 2.5 if you sum them all and divide by 4.
With that method it is:
mean([1, 2, 3, 4]) = mean([1.5, 3, 4]) = mean([2.25, 4]) = 3.125
X = Mean([a,b,c]) = (a+b+c)/3
Y = YourFunction([a,b,c]) = (((a+b)/2)+c)/2 = (a+b+2c)/4
X does not equal Y. It doesn't matter if the reduce is left or right, btw, it's still wrong.