Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84fc708

Browse files
committed
merge
2 parents 9809ca9 + 6480168 commit 84fc708

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

Doc/library/functools.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ The :mod:`functools` module defines the following functions:
205205
a default when the sequence is empty. If *initializer* is not given and
206206
*sequence* contains only one item, the first item is returned.
207207

208+
Equivalent to::
209+
210+
def reduce(function, iterable, initializer=None):
211+
it = iter(iterable)
212+
if initializer is None:
213+
value = next(it)
214+
else:
215+
value = initializer
216+
for element in it:
217+
value = function(value, element)
218+
return value
219+
208220

209221
.. decorator:: singledispatch(default)
210222

Doc/library/itertools.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ loops that truncate the stream.
135135
'0.93', '0.25', '0.71', '0.79', '0.63', '0.88', '0.39', '0.91', '0.32',
136136
'0.83', '0.54', '0.95', '0.20', '0.60', '0.91', '0.30', '0.80', '0.60']
137137

138+
See :func:`functools.reduce` for a similar function that returns only the
139+
final accumulated value.
140+
138141
.. versionadded:: 3.2
139142

140143
.. versionchanged:: 3.3

0 commit comments

Comments
 (0)