[Python-checkins] r69756 - in python/branches/release30-maint: Doc/library/functions.rst Doc/library/itertools.rst Lib/test/test_itertools.py
raymond.hettinger
python-checkins at python.org
Thu Feb 19 05:49:40 CET 2009
Author: raymond.hettinger
Date: Thu Feb 19 05:49:39 2009
New Revision: 69756
Log:
Add some cross-references to the docs. Simplify the python code equivalent for zip(). Supply an optional argument for the nth() recipe.
Modified:
python/branches/release30-maint/Doc/library/functions.rst
python/branches/release30-maint/Doc/library/itertools.rst
python/branches/release30-maint/Lib/test/test_itertools.py
Modified: python/branches/release30-maint/Doc/library/functions.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/functions.rst (original)
+++ python/branches/release30-maint/Doc/library/functions.rst Thu Feb 19 05:49:39 2009
@@ -380,6 +380,9 @@
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 @@
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])
@@ -948,7 +952,8 @@
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]])
@@ -1025,7 +1030,8 @@
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]])
@@ -1137,8 +1143,7 @@
# 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
Modified: python/branches/release30-maint/Doc/library/itertools.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/itertools.rst (original)
+++ python/branches/release30-maint/Doc/library/itertools.rst Thu Feb 19 05:49:39 2009
@@ -529,9 +529,9 @@
"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"
Modified: python/branches/release30-maint/Lib/test/test_itertools.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_itertools.py (original)
+++ python/branches/release30-maint/Lib/test/test_itertools.py Thu Feb 19 05:49:39 2009
@@ -1219,9 +1219,9 @@
... "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"
More information about the Python-checkins
mailing list