10 Jun
2018
10 Jun
'18
3:06 a.m.
Hi, I have found bug in functools.reduce (Python V 3.6.5). The function ignores the value of initializer, if initializer is zero. Below is the example code import functools as f ar = [2, 5, 4, 1, 3] out = f.reduce(lambda prev, curr: prev < curr and prev or curr, ar, 0) print(out)
Expected: 0 Actual: 1
out2 = f.reduce(lambda prev, curr: prev < curr and prev or curr, ar, -1) print(out2)
Expected: -1 Actual: -1
Best Regards, Witthawat P.