summaryrefslogtreecommitdiffstats
path: root/Doc/library/itertools.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-03 02:09:34 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-03 02:09:34 (GMT)
commitd8ff4658fb5884d9536732f7f34848aadd519e17 (patch)
tree94c68d7d5582bbddcd56de6a74a742c5144f4bfd /Doc/library/itertools.rst
parenta7a0e1a0f4248289e00284c115fff54b11f18a53 (diff)
downloadcpython-d8ff4658fb5884d9536732f7f34848aadd519e17.zip
cpython-d8ff4658fb5884d9536732f7f34848aadd519e17.tar.gz
cpython-d8ff4658fb5884d9536732f7f34848aadd519e17.tar.bz2
Simplify the signature for itertools.accumulate() to match numpy. Handle one item iterable the same way as min()/max().
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r--Doc/library/itertools.rst14
1 files changed, 8 insertions, 6 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 56eb452..befc6be 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -90,13 +90,15 @@ loops that truncate the stream.
parameter (which defaults to :const:`0`). Elements may be any addable type
including :class:`Decimal` or :class:`Fraction`. Equivalent to::
- def accumulate(iterable, start=0):
+ def accumulate(iterable):
'Return running totals'
- # accumulate([1,2,3,4,5]) --> 1 3 6 10 15
- total = start
- for element in iterable:
- total += element
- yield total
+ # accumulate([1,2,3,4,5]) --> 1 3 6 10 15
+ it = iter(iterable)
+ total = next(it)
+ yield total
+ for element in it:
+ total += element
+ yield total
.. versionadded:: 3.2