]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add some cross-references to the docs. Simplify the python code equivalent for zip...
authorRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 04:45:07 +0000 (04:45 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 04:45:07 +0000 (04:45 +0000)
Doc/library/functions.rst
Doc/library/itertools.rst
Lib/test/test_itertools.py

index f9205b624d32c91871228738555bbbdbb78b6978..39aab162a800f747fa081852da82c65231f7d3fd 100644 (file)
@@ -380,6 +380,9 @@ are always available.  They are listed here in alphabetical order.
    not ``None`` and ``(item for item in iterable if item)`` if function is
    ``None``.
 
+   See :func:`itertools.filterfalse` for the complementary function that returns
+   elements of *iterable* for which *function* returns false.
+
 
 .. function:: float([x])
 
@@ -595,7 +598,8 @@ are always available.  They are listed here in alphabetical order.
    yielding the results.  If additional *iterable* arguments are passed,
    *function* must take that many arguments and is applied to the items from all
    iterables in parallel.  With multiple iterables, the iterator stops when the
-   shortest iterable is exhausted.
+   shortest iterable is exhausted.  For cases where the function inputs are
+   already arranged into argument tuples, see :func:`itertools.starmap`\.
 
 
 .. function:: max(iterable[, args...], *[, key])
@@ -953,7 +957,8 @@ are always available.  They are listed here in alphabetical order.
    default).  They have no other explicit functionality; however they are used by
    Numerical Python and other third party extensions.  Slice objects are also
    generated when extended indexing syntax is used.  For example:
-   ``a[start:stop:step]`` or ``a[start:stop, i]``.
+   ``a[start:stop:step]`` or ``a[start:stop, i]``.  See :func:`itertools.islice`
+   for an alternate version that returns an iterator.
 
 
 .. function:: sorted(iterable[, key[, reverse]])
@@ -1030,7 +1035,8 @@ are always available.  They are listed here in alphabetical order.
    Sums *start* and the items of an *iterable* from left to right and returns the
    total.  *start* defaults to ``0``. The *iterable*'s items are normally numbers,
    and are not allowed to be strings.  The fast, correct way to concatenate a
-   sequence of strings is by calling ``''.join(sequence)``.
+   sequence of strings is by calling ``''.join(sequence)``.  To add floating
+   point values with extended precision, see :func:`math.fsum`\.
 
 
 .. function:: super([type[, object-or-type]])
@@ -1145,8 +1151,7 @@ are always available.  They are listed here in alphabetical order.
           # zip('ABCD', 'xy') --> Ax By
           iterables = map(iter, iterables)
           while iterables:
-              result = [it.next() for it in iterables]
-              yield tuple(result)
+              yield tuple(map(next, iterables))
 
    The left-to-right evaluation order of the iterables is guaranteed. This
    makes possible an idiom for clustering a data series into n-length groups
index 491cb184a18200dc0cc912b9f66d3d1dd8e23141..32ad792fb27257d2eaba98808166778e181d40df 100644 (file)
@@ -615,9 +615,9 @@ which incur interpreter overhead.
        "Return function(0), function(1), ..."
        return map(function, count(start))
 
-   def nth(iterable, n):
-       "Returns the nth item or None"
-       return next(islice(iterable, n, None), None)
+   def nth(iterable, n, default=None):
+       "Returns the nth item or a default value"
+       return next(islice(iterable, n, None), default)
 
    def quantify(iterable, pred=bool):
        "Count how many times the predicate is true"
index 84924843a39437a6116585984175afea6c32ceae..cf0ca24d273f70232e4e228e377c25f0e39004e0 100644 (file)
@@ -1419,9 +1419,9 @@ Samuele
 ...     "Return function(0), function(1), ..."
 ...     return map(function, count(start))
 
->>> def nth(iterable, n):
-...     "Returns the nth item or None"
-...     return next(islice(iterable, n, None), None)
+>>> def nth(iterable, n, default=None):
+...     "Returns the nth item or a default value"
+...     return next(islice(iterable, n, None), default)
 
 >>> def quantify(iterable, pred=bool):
 ...     "Count how many times the predicate is true"