summaryrefslogtreecommitdiffstats
path: root/Doc/howto/functional.rst
diff options
context:
space:
mode:
authorcsabella <cheryl.sabella@gmail.com>2017-06-05 03:12:23 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-06-05 03:12:23 (GMT)
commitce40550acd3a8928bb6fef4d4e73642a8a69745d (patch)
tree1ed87d1540f4e380dbe0ed01299b5169a65c9baa /Doc/howto/functional.rst
parent86eb93fae6fc5bf121de815b82697f2bc5bc126c (diff)
downloadcpython-ce40550acd3a8928bb6fef4d4e73642a8a69745d.zip
cpython-ce40550acd3a8928bb6fef4d4e73642a8a69745d.tar.gz
cpython-ce40550acd3a8928bb6fef4d4e73642a8a69745d.tar.bz2
bpo-30538: Update count() in Functional Programming HOWTO (GH-1919) (GH-1943)
* bpo-30538: Update count() in Functional HOWTO * bpo-30538: Update enumerate() arguments in Functional HOWTO (cherry picked from commit 9be4ff359daa67cde6246494f643ed7cd2825d46)
Diffstat (limited to 'Doc/howto/functional.rst')
-rw-r--r--Doc/howto/functional.rst23
1 files changed, 14 insertions, 9 deletions
diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst
index a82dca7..4060181 100644
--- a/Doc/howto/functional.rst
+++ b/Doc/howto/functional.rst
@@ -653,8 +653,9 @@ This can also be written as a list comprehension:
[0, 2, 4, 6, 8]
-:func:`enumerate(iter) <enumerate>` counts off the elements in the iterable,
-returning 2-tuples containing the count and each element. ::
+:func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the
+iterable returning 2-tuples containing the count (from *start*) and
+each element. ::
>>> for item in enumerate(['subject', 'verb', 'object']):
... print(item)
@@ -747,14 +748,16 @@ The module's functions fall into a few broad classes:
Creating new iterators
----------------------
-:func:`itertools.count(n) <itertools.count>` returns an infinite stream of
-integers, increasing by 1 each time. You can optionally supply the starting
-number, which defaults to 0::
+:func:`itertools.count(start, step) <itertools.count>` returns an infinite
+stream of evenly spaced values. You can optionally supply the starting number,
+which defaults to 0, and the interval between numbers, which defaults to 1::
itertools.count() =>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
itertools.count(10) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
+ itertools.count(10, 5) =>
+ 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, ...
:func:`itertools.cycle(iter) <itertools.cycle>` saves a copy of the contents of
a provided iterable and returns a new iterator that returns its elements from
@@ -1060,10 +1063,10 @@ write the obvious :keyword:`for` loop::
for i in [1,2,3]:
product *= i
-A related function is `itertools.accumulate(iterable, func=operator.add) <itertools.accumulate`.
-It performs the same calculation, but instead of returning only the
-final result, :func:`accumulate` returns an iterator that also yields
-each partial result::
+A related function is :func:`itertools.accumulate(iterable, func=operator.add)
+<itertools.accumulate>`. It performs the same calculation, but instead of
+returning only the final result, :func:`accumulate` returns an iterator that
+also yields each partial result::
itertools.accumulate([1,2,3,4,5]) =>
1, 3, 6, 10, 15
@@ -1235,6 +1238,8 @@ Python documentation
Documentation for the :mod:`itertools` module.
+Documentation for the :mod:`functools` module.
+
Documentation for the :mod:`operator` module.
:pep:`289`: "Generator Expressions"