Skip to content

Commit da36f67

Browse files
authored
Remove ambiguous part in docstring of functools.reduce()
Old description could be read that "initial" will only be used if "iterable" is empty. This is not the case. Plus include additional sentence from docs.python.org
1 parent a852c7b commit da36f67

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/functools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ def reduce(function, sequence, initial=_initial_missing):
241241
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.
242242
243243
This effectively reduces the iterable to a single value. If initial is present,
244-
it is placed before the items of the iterable in the calculation, and serves as
245-
a default when the iterable is empty.
244+
it is placed before the items of the iterable in the calculation. If the iterable is empty and
245+
initial is given, initial will be returned. If initial is not given and iterable contains only
246+
one item, the first item is returned.
246247
247248
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
248249
calculates ((((1 + 2) + 3) + 4) + 5).

0 commit comments

Comments
 (0)