>>> reduce(lambda x, y: x*int(y), ['2', '3', '4']) '222222222222'
Ok, here's what happens:
At the first reduction stage, the following calculation is performed: '2' * 3 . Since the first operand is a string, it just repeats 3 times. That way you get '222' .
In the second reduction step, this value is multiplied by 4: '222' * 4 . Again, the line is repeated four times, resulting in '222222222222' , which is exactly the result you got.
You could avoid this by converting x to int also (calling int(x) ) or by matching list items using integer conversion in the first place (I actually think this is more elegant):
>>> reduce(lambda x, y: x * y, map(int, ['2', '3', '4'])) 24
source share