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

Skip to content

Commit 819581b

Browse files
committed
Issue 25926: Clarify that the pure python equivalents are only approximate.
1 parent fe289c0 commit 819581b

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

Doc/library/itertools.rst

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ loops that truncate the stream.
9797
:class:`~fractions.Fraction`.) If the input iterable is empty, the
9898
output iterable will also be empty.
9999

100-
Equivalent to::
100+
Roughly equivalent to::
101101

102102
def accumulate(iterable, func=operator.add):
103103
'Return running totals'
@@ -156,7 +156,7 @@ loops that truncate the stream.
156156
Make an iterator that returns elements from the first iterable until it is
157157
exhausted, then proceeds to the next iterable, until all of the iterables are
158158
exhausted. Used for treating consecutive sequences as a single sequence.
159-
Equivalent to::
159+
Roughly equivalent to::
160160

161161
def chain(*iterables):
162162
# chain('ABC', 'DEF') --> A B C D E F
@@ -189,7 +189,7 @@ loops that truncate the stream.
189189
value. So if the input elements are unique, there will be no repeat
190190
values in each combination.
191191

192-
Equivalent to::
192+
Roughly equivalent to::
193193

194194
def combinations(iterable, r):
195195
# combinations('ABCD', 2) --> AB AC AD BC BD CD
@@ -238,7 +238,7 @@ loops that truncate the stream.
238238
value. So if the input elements are unique, the generated combinations
239239
will also be unique.
240240

241-
Equivalent to::
241+
Roughly equivalent to::
242242

243243
def combinations_with_replacement(iterable, r):
244244
# combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC
@@ -278,7 +278,7 @@ loops that truncate the stream.
278278
Make an iterator that filters elements from *data* returning only those that
279279
have a corresponding element in *selectors* that evaluates to ``True``.
280280
Stops when either the *data* or *selectors* iterables has been exhausted.
281-
Equivalent to::
281+
Roughly equivalent to::
282282

283283
def compress(data, selectors):
284284
# compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
@@ -291,7 +291,7 @@ loops that truncate the stream.
291291

292292
Make an iterator that returns evenly spaced values starting with number *start*. Often
293293
used as an argument to :func:`map` to generate consecutive data points.
294-
Also, used with :func:`zip` to add sequence numbers. Equivalent to::
294+
Also, used with :func:`zip` to add sequence numbers. Roughly equivalent to::
295295

296296
def count(start=0, step=1):
297297
# count(10) --> 10 11 12 13 14 ...
@@ -312,7 +312,7 @@ loops that truncate the stream.
312312

313313
Make an iterator returning elements from the iterable and saving a copy of each.
314314
When the iterable is exhausted, return elements from the saved copy. Repeats
315-
indefinitely. Equivalent to::
315+
indefinitely. Roughly equivalent to::
316316

317317
def cycle(iterable):
318318
# cycle('ABCD') --> A B C D A B C D A B C D ...
@@ -333,7 +333,7 @@ loops that truncate the stream.
333333
Make an iterator that drops elements from the iterable as long as the predicate
334334
is true; afterwards, returns every element. Note, the iterator does not produce
335335
*any* output until the predicate first becomes false, so it may have a lengthy
336-
start-up time. Equivalent to::
336+
start-up time. Roughly equivalent to::
337337

338338
def dropwhile(predicate, iterable):
339339
# dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1
@@ -349,7 +349,7 @@ loops that truncate the stream.
349349

350350
Make an iterator that filters elements from iterable returning only those for
351351
which the predicate is ``False``. If *predicate* is ``None``, return the items
352-
that are false. Equivalent to::
352+
that are false. Roughly equivalent to::
353353

354354
def filterfalse(predicate, iterable):
355355
# filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
@@ -386,7 +386,7 @@ loops that truncate the stream.
386386
groups.append(list(g)) # Store group iterator as a list
387387
uniquekeys.append(k)
388388

389-
:func:`groupby` is equivalent to::
389+
:func:`groupby` is roughly equivalent to::
390390

391391
class groupby:
392392
# [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
@@ -426,7 +426,7 @@ loops that truncate the stream.
426426
specified position. Unlike regular slicing, :func:`islice` does not support
427427
negative values for *start*, *stop*, or *step*. Can be used to extract related
428428
fields from data where the internal structure has been flattened (for example, a
429-
multi-line report may list a name field on every third line). Equivalent to::
429+
multi-line report may list a name field on every third line). Roughly equivalent to::
430430

431431
def islice(iterable, *args):
432432
# islice('ABCDEFG', 2) --> A B
@@ -464,7 +464,7 @@ loops that truncate the stream.
464464
value. So if the input elements are unique, there will be no repeat
465465
values in each permutation.
466466

467-
Equivalent to::
467+
Roughly equivalent to::
468468

469469
def permutations(iterable, r=None):
470470
# permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
@@ -510,7 +510,7 @@ loops that truncate the stream.
510510

511511
Cartesian product of input iterables.
512512

513-
Equivalent to nested for-loops in a generator expression. For example,
513+
Roughly equivalent to nested for-loops in a generator expression. For example,
514514
``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
515515

516516
The nested loops cycle like an odometer with the rightmost element advancing
@@ -522,7 +522,7 @@ loops that truncate the stream.
522522
repetitions with the optional *repeat* keyword argument. For example,
523523
``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``.
524524

525-
This function is equivalent to the following code, except that the
525+
This function is roughly equivalent to the following code, except that the
526526
actual implementation does not build up intermediate results in memory::
527527

528528
def product(*args, repeat=1):
@@ -541,7 +541,9 @@ loops that truncate the stream.
541541
Make an iterator that returns *object* over and over again. Runs indefinitely
542542
unless the *times* argument is specified. Used as argument to :func:`map` for
543543
invariant parameters to the called function. Also used with :func:`zip` to
544-
create an invariant part of a tuple record. Equivalent to::
544+
create an invariant part of a tuple record.
545+
546+
Roughly equivalent to::
545547

546548
def repeat(object, times=None):
547549
# repeat(10, 3) --> 10 10 10
@@ -564,7 +566,7 @@ loops that truncate the stream.
564566
the iterable. Used instead of :func:`map` when argument parameters are already
565567
grouped in tuples from a single iterable (the data has been "pre-zipped"). The
566568
difference between :func:`map` and :func:`starmap` parallels the distinction
567-
between ``function(a,b)`` and ``function(*c)``. Equivalent to::
569+
between ``function(a,b)`` and ``function(*c)``. Roughly equivalent to::
568570

569571
def starmap(function, iterable):
570572
# starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000
@@ -575,7 +577,7 @@ loops that truncate the stream.
575577
.. function:: takewhile(predicate, iterable)
576578

577579
Make an iterator that returns elements from the iterable as long as the
578-
predicate is true. Equivalent to::
580+
predicate is true. Roughly equivalent to::
579581

580582
def takewhile(predicate, iterable):
581583
# takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4
@@ -588,7 +590,7 @@ loops that truncate the stream.
588590

589591
.. function:: tee(iterable, n=2)
590592

591-
Return *n* independent iterators from a single iterable. Equivalent to::
593+
Return *n* independent iterators from a single iterable. Roughly equivalent to::
592594

593595
def tee(iterable, n=2):
594596
it = iter(iterable)
@@ -619,7 +621,7 @@ loops that truncate the stream.
619621

620622
Make an iterator that aggregates elements from each of the iterables. If the
621623
iterables are of uneven length, missing values are filled-in with *fillvalue*.
622-
Iteration continues until the longest iterable is exhausted. Equivalent to::
624+
Iteration continues until the longest iterable is exhausted. Roughly equivalent to::
623625

624626
class ZipExhausted(Exception):
625627
pass

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ Ralf Schmitt
13031303
Michael Schneider
13041304
Peter Schneider-Kamp
13051305
Arvin Schnell
1306+
Nofar Schnider
13061307
Scott Schram
13071308
Robin Schreiber
13081309
Chad J. Schroeder

0 commit comments

Comments
 (0)