diff options
author | Raymond Hettinger <python@rcn.com> | 2013-10-12 23:04:17 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-10-12 23:04:17 (GMT) |
commit | 64801680d3b8fe148da331b68923f06f626f01f1 (patch) | |
tree | 03ffa5783ca8198c359b73ca6300e6729e91a0d5 /Doc/library/functools.rst | |
parent | 5d4121a6311065723426b977a8f080518cdf8738 (diff) | |
download | cpython-64801680d3b8fe148da331b68923f06f626f01f1.zip cpython-64801680d3b8fe148da331b68923f06f626f01f1.tar.gz cpython-64801680d3b8fe148da331b68923f06f626f01f1.tar.bz2 |
Issue #19202: Add cross-reference and a rough code equivalent
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 d8fcf0f..3c946e3 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -185,6 +185,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 + .. function:: update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES) |