[docs] Bug in functools.reduce
Witthawat P.
silverparasol at hotmail.com
Sat Jun 9 23:06:11 EDT 2018
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20180610/1eab404d/attachment-0001.html>
More information about the docs
mailing list