Commit 84fc7081 authored by Raymond Hettinger's avatar Raymond Hettinger

merge

parents 9809ca9d 64801680
...@@ -205,6 +205,18 @@ The :mod:`functools` module defines the following functions: ...@@ -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 a default when the sequence is empty. If *initializer* is not given and
*sequence* contains only one item, the first item is returned. *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) .. decorator:: singledispatch(default)
......
...@@ -135,6 +135,9 @@ loops that truncate the stream. ...@@ -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.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'] '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 .. versionadded:: 3.2
.. versionchanged:: 3.3 .. versionchanged:: 3.3
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment