[docs] Error in functools.reduce docs

Dongkyu Choi creditchoi at gmail.com
Sun Jul 8 17:05:08 EDT 2018

Hi, I report error at the


specifically, at “If the optional initializer is present, it is placed
before the items of the sequence in the calculation, and [serves as a
default when the sequence is empty]. If initializer is not given and
sequence contains only one item, the first item is returned. (bracket is
added by me for emphasis)”

Actually, it should be stated as ‘serves as a default to be run before the
lambda reads the given sequence.’

For example, at the code

def string_to_int(s):
return functools.reduce(lambda running_sum, c: running_sum * 10 +
string.digits.index(c), s[s[0] == '-':], 0) * (-1 if s[0] == '-' else 1)

he 0 does the job setting running_sum, c
even before it traverses the given string,
​ ​
not restricted to the empty string case. Precisely,
 if we have
s =
we need to have ru
nning_sum=0, c=0
​ ​
initially, to make it (0*10+index(0)) … as the running_sum cannot be str,
if so I get the initializer does the job of setting all the argument of
lambda: function as initializer.

Please consider this. Thanks.

Best regards,


+1 (929) 302-9410
creditchoi at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20180708/7b03d8b2/attachment-0001.html>

More information about the docs mailing list