Skip to content

Commit 988cdcc

Browse files
authored
[3.13] Itertool docs: Minor clarifications, wording tweaks, spacing, and active voice. (gh-124690) (gh-125148)
Minor clarifications, wording tweaks, spacing, and active voice.
1 parent 7bc99dd commit 988cdcc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Doc/library/itertools.rst

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Iterator Arguments Results
5858
:func:`compress` data, selectors (d[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) → A C E F``
5959
:func:`dropwhile` predicate, seq seq[n], seq[n+1], starting when predicate fails ``dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8``
6060
:func:`filterfalse` predicate, seq elements of seq where predicate(elem) fails ``filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8``
61-
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v)
61+
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v) ``groupby(['A','B','DEF'], len) → (1, A B) (3, DEF)``
6262
:func:`islice` seq, [start,] stop [, step] elements from seq[start:stop:step] ``islice('ABCDEFG', 2, None) → C D E F G``
6363
:func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') → AB BC CD DE EF FG``
6464
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000``
@@ -93,7 +93,7 @@ Examples Results
9393
Itertool Functions
9494
------------------
9595

96-
The following module functions all construct and return iterators. Some provide
96+
The following functions all construct and return iterators. Some provide
9797
streams of infinite length, so they should only be accessed by functions or
9898
loops that truncate the stream.
9999

@@ -131,11 +131,12 @@ loops that truncate the stream.
131131
total = function(total, element)
132132
yield total
133133

134-
The *function* argument can be set to :func:`min` for a running
135-
minimum, :func:`max` for a running maximum, or :func:`operator.mul`
136-
for a running product. `Amortization tables
137-
<https://www.ramseysolutions.com/real-estate/amortization-schedule>`_
138-
can be built by accumulating interest and applying payments:
134+
To compute a running minimum, set *function* to :func:`min`.
135+
For a running maximum, set *function* to :func:`max`.
136+
Or for a running product, set *function* to :func:`operator.mul`.
137+
To build an `Amortization table
138+
<https://www.ramseysolutions.com/real-estate/amortization-schedule>`_,
139+
accumulate the interest and apply payments:
139140

140141
.. doctest::
141142

@@ -202,10 +203,10 @@ loops that truncate the stream.
202203

203204
.. function:: chain(*iterables)
204205

205-
Make an iterator that returns elements from the first iterable until it is
206-
exhausted, then proceeds to the next iterable, until all of the iterables are
207-
exhausted. Used for treating consecutive sequences as a single sequence.
208-
Roughly equivalent to::
206+
Make an iterator that returns elements from the first iterable until
207+
it is exhausted, then proceeds to the next iterable, until all of the
208+
iterables are exhausted. This combines multiple data sources into a
209+
single iterator. Roughly equivalent to::
209210

210211
def chain(*iterables):
211212
# chain('ABC', 'DEF') → A B C D E F
@@ -353,10 +354,12 @@ loops that truncate the stream.
353354

354355
def cycle(iterable):
355356
# cycle('ABCD') → A B C D A B C D A B C D ...
357+
356358
saved = []
357359
for element in iterable:
358360
yield element
359361
saved.append(element)
362+
360363
while saved:
361364
for element in saved:
362365
yield element
@@ -396,8 +399,10 @@ loops that truncate the stream.
396399

397400
def filterfalse(predicate, iterable):
398401
# filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8
402+
399403
if predicate is None:
400404
predicate = bool
405+
401406
for x in iterable:
402407
if not predicate(x):
403408
yield x
@@ -474,7 +479,7 @@ loops that truncate the stream.
474479
If *start* is zero or ``None``, iteration starts at zero. Otherwise,
475480
elements from the iterable are skipped until *start* is reached.
476481

477-
If *stop* is ``None``, iteration continues until the iterable is
482+
If *stop* is ``None``, iteration continues until the input is
478483
exhausted, if at all. Otherwise, it stops at the specified position.
479484

480485
If *step* is ``None``, the step defaults to one. Elements are returned
@@ -520,8 +525,10 @@ loops that truncate the stream.
520525

521526
def pairwise(iterable):
522527
# pairwise('ABCDEFG') → AB BC CD DE EF FG
528+
523529
iterator = iter(iterable)
524530
a = next(iterator, None)
531+
525532
for b in iterator:
526533
yield a, b
527534
a = b
@@ -584,7 +591,8 @@ loops that truncate the stream.
584591

585592
.. function:: product(*iterables, repeat=1)
586593

587-
Cartesian product of input iterables.
594+
`Cartesian product <https://en.wikipedia.org/wiki/Cartesian_product>`_
595+
of the input iterables.
588596

589597
Roughly equivalent to nested for-loops in a generator expression. For example,
590598
``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.

0 commit comments

Comments
 (0)