@@ -403,25 +403,27 @@ The :mod:`functools` module defines the following functions:
403403 .. versionadded :: 3.4
404404
405405
406- .. function :: reduce(function, iterable[, initializer] )
406+ .. function :: reduce(function, iterable[, initial], / )
407407
408408 Apply *function * of two arguments cumulatively to the items of *iterable *, from
409409 left to right, so as to reduce the iterable to a single value. For example,
410410 ``reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) `` calculates ``((((1+2)+3)+4)+5) ``.
411411 The left argument, *x *, is the accumulated value and the right argument, *y *, is
412- the update value from the *iterable *. If the optional *initializer * is present,
412+ the update value from the *iterable *. If the optional *initial * is present,
413413 it is placed before the items of the iterable in the calculation, and serves as
414- a default when the iterable is empty. If *initializer * is not given and
414+ a default when the iterable is empty. If *initial * is not given and
415415 *iterable * contains only one item, the first item is returned.
416416
417417 Roughly equivalent to::
418418
419- def reduce(function, iterable, initializer=None):
419+ initial_missing = object()
420+
421+ def reduce(function, iterable, initial=initial_missing, /):
420422 it = iter(iterable)
421- if initializer is None :
423+ if initial is initial_missing :
422424 value = next(it)
423425 else:
424- value = initializer
426+ value = initial
425427 for element in it:
426428 value = function(value, element)
427429 return value
0 commit comments