]> granicus.if.org Git - python/commitdiff
Add some cross-references to the docs. Simplify the python code equivalent for izip...
authorRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 05:34:35 +0000 (05:34 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 05:34:35 +0000 (05:34 +0000)
Doc/library/functions.rst
Doc/library/itertools.rst
Lib/test/test_itertools.py

index fbb3f87367e9b6d7dd1c38886ca7fabd0ea23630..9de9db67291404476c84216d054e51bd17287f08 100644 (file)
@@ -397,6 +397,9 @@ available.  They are listed here in alphabetical order.
    iterable if function(item)]`` if function is 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])
 
@@ -1077,7 +1080,8 @@ 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[, cmp[, key[, reverse]]])
@@ -1160,6 +1164,7 @@ available.  They are listed here in alphabetical order.
    and are not allowed to be strings.  The fast, correct way to concatenate a
    sequence of strings is by calling ``''.join(sequence)``. Note that
    ``sum(range(n), m)`` is equivalent to ``reduce(operator.add, range(n), m)``
+   To add floating point values with extended precision, see :func:`math.fsum`\.
 
    .. versionadded:: 2.3
 
@@ -1329,7 +1334,9 @@ available.  They are listed here in alphabetical order.
       :func:`xrange` is intended to be simple and fast. Implementations may impose
       restrictions to achieve this. The C implementation of Python restricts all
       arguments to native C longs ("short" Python integers), and also requires that
-      the number of elements fit in a native C long.
+      the number of elements fit in a native C long.  If a larger range is needed,
+      an alternate version can be crafted using the :mod:`itertools` module:
+      ``islice(count(start, step), (stop-start+step-1)//step)``.
 
 
 .. function:: zip([iterable, ...])
index 6fa1978af8597c3e12cc49562600d8cee3056c95..299d7693e0596b155b8559f826aaa3847c41a9ca 100644 (file)
@@ -427,8 +427,7 @@ loops that truncate the stream.
           # izip('ABCD', 'xy') --> Ax By
           iterables = map(iter, iterables)
           while iterables:
-              result = [it.next() for it in iterables]
-              yield tuple(result)
+              yield yield tuple(map(next, iterables))
 
    .. versionchanged:: 2.4
       When no iterables are specified, returns a zero length iterator instead of
@@ -702,9 +701,9 @@ which incur interpreter overhead.
        "Return function(0), function(1), ..."
        return imap(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 81a052b862df5f560b5a0cbbc298cfc78ceaf547..9eb138954d2572cc10721cea38dc484515944fb0 100644 (file)
@@ -1401,9 +1401,9 @@ Samuele
 ...     "Return function(0), function(1), ..."
 ...     return imap(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"