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

Skip to content

Commit cdf8ba3

Browse files
committed
Add some cross-references to the docs. Simplify the python code equivalent for zip(). Supply an optional argument for the nth() recipe.
1 parent d75fcb4 commit cdf8ba3

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

Doc/library/functions.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ are always available. They are listed here in alphabetical order.
380380
not ``None`` and ``(item for item in iterable if item)`` if function is
381381
``None``.
382382

383+
See :func:`itertools.filterfalse` for the complementary function that returns
384+
elements of *iterable* for which *function* returns false.
385+
383386

384387
.. function:: float([x])
385388

@@ -595,7 +598,8 @@ are always available. They are listed here in alphabetical order.
595598
yielding the results. If additional *iterable* arguments are passed,
596599
*function* must take that many arguments and is applied to the items from all
597600
iterables in parallel. With multiple iterables, the iterator stops when the
598-
shortest iterable is exhausted.
601+
shortest iterable is exhausted. For cases where the function inputs are
602+
already arranged into argument tuples, see :func:`itertools.starmap`\.
599603

600604

601605
.. function:: max(iterable[, args...], *[, key])
@@ -953,7 +957,8 @@ are always available. They are listed here in alphabetical order.
953957
default). They have no other explicit functionality; however they are used by
954958
Numerical Python and other third party extensions. Slice objects are also
955959
generated when extended indexing syntax is used. For example:
956-
``a[start:stop:step]`` or ``a[start:stop, i]``.
960+
``a[start:stop:step]`` or ``a[start:stop, i]``. See :func:`itertools.islice`
961+
for an alternate version that returns an iterator.
957962

958963

959964
.. function:: sorted(iterable[, key[, reverse]])
@@ -1030,7 +1035,8 @@ are always available. They are listed here in alphabetical order.
10301035
Sums *start* and the items of an *iterable* from left to right and returns the
10311036
total. *start* defaults to ``0``. The *iterable*'s items are normally numbers,
10321037
and are not allowed to be strings. The fast, correct way to concatenate a
1033-
sequence of strings is by calling ``''.join(sequence)``.
1038+
sequence of strings is by calling ``''.join(sequence)``. To add floating
1039+
point values with extended precision, see :func:`math.fsum`\.
10341040

10351041

10361042
.. function:: super([type[, object-or-type]])
@@ -1145,8 +1151,7 @@ are always available. They are listed here in alphabetical order.
11451151
# zip('ABCD', 'xy') --> Ax By
11461152
iterables = map(iter, iterables)
11471153
while iterables:
1148-
result = [it.next() for it in iterables]
1149-
yield tuple(result)
1154+
yield tuple(map(next, iterables))
11501155

11511156
The left-to-right evaluation order of the iterables is guaranteed. This
11521157
makes possible an idiom for clustering a data series into n-length groups

Doc/library/itertools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ which incur interpreter overhead.
615615
"Return function(0), function(1), ..."
616616
return map(function, count(start))
617617

618-
def nth(iterable, n):
619-
"Returns the nth item or None"
620-
return next(islice(iterable, n, None), None)
618+
def nth(iterable, n, default=None):
619+
"Returns the nth item or a default value"
620+
return next(islice(iterable, n, None), default)
621621

622622
def quantify(iterable, pred=bool):
623623
"Count how many times the predicate is true"

Lib/test/test_itertools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,9 +1419,9 @@ def __init__(self, newarg=None, *args):
14191419
... "Return function(0), function(1), ..."
14201420
... return map(function, count(start))
14211421
1422-
>>> def nth(iterable, n):
1423-
... "Returns the nth item or None"
1424-
... return next(islice(iterable, n, None), None)
1422+
>>> def nth(iterable, n, default=None):
1423+
... "Returns the nth item or a default value"
1424+
... return next(islice(iterable, n, None), default)
14251425
14261426
>>> def quantify(iterable, pred=bool):
14271427
... "Count how many times the predicate is true"

0 commit comments

Comments
 (0)