summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-10-12 23:04:39 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-10-12 23:04:39 (GMT)
commit84fc7081f55f517062b35d0e0628cdfa4f1b9d55 (patch)
treee614e95263b2c531181f20d6f54fd7820ab10ce4 /Doc/library
parent9809ca9d9ea96fdda69fca3ead2d0b765c55bc1a (diff)
parent64801680d3b8fe148da331b68923f06f626f01f1 (diff)
downloadcpython-84fc7081f55f517062b35d0e0628cdfa4f1b9d55.zip
cpython-84fc7081f55f517062b35d0e0628cdfa4f1b9d55.tar.gz
cpython-84fc7081f55f517062b35d0e0628cdfa4f1b9d55.tar.bz2
merge
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/functools.rst12
-rw-r--r--Doc/library/itertools.rst3
2 files changed, 15 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)
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 25f34bf..0156c05 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -135,6 +135,9 @@ loops that truncate the stream.
'0.93', '0.25', '0.71', '0.79', '0.63', '0.88', '0.39', '0.91', '0.32',
'0.83', '0.54', '0.95', '0.20', '0.60', '0.91', '0.30', '0.80', '0.60']
+ See :func:`functools.reduce` for a similar function that returns only the
+ final accumulated value.
+
.. versionadded:: 3.2
.. versionchanged:: 3.3