diff options
Diffstat (limited to 'Doc/library/functools.rst')
-rw-r--r-- | Doc/library/functools.rst | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 5eb86ec..14e1351 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -205,6 +205,18 @@ The :mod:`functools` module defines the following functions: a default when the sequence is empty. If *initializer* is not given and *sequence* contains only one item, the first item is returned. + Equivalent to:: + + def reduce(function, iterable, initializer=None): + it = iter(iterable) + if initializer is None: + value = next(it) + else: + value = initializer + for element in it: + value = function(value, element) + return value + .. decorator:: singledispatch(default) |