[Python-checkins] r69005 - python/branches/py3k/Doc/library/itertools.rst

raymond.hettinger python-checkins at python.org
Tue Jan 27 05:42:49 CET 2009


Author: raymond.hettinger
Date: Tue Jan 27 05:42:48 2009
New Revision: 69005

Log:
Put functions back in alphabetical order.

Modified:
   python/branches/py3k/Doc/library/itertools.rst

Modified: python/branches/py3k/Doc/library/itertools.rst
==============================================================================
--- python/branches/py3k/Doc/library/itertools.rst	(original)
+++ python/branches/py3k/Doc/library/itertools.rst	Tue Jan 27 05:42:48 2009
@@ -245,6 +245,20 @@
           for x in iterable:
               yield x
 
+.. function:: filterfalse(predicate, iterable)
+
+   Make an iterator that filters elements from iterable returning only those for
+   which the predicate is ``False``. If *predicate* is ``None``, return the items
+   that are false. Equivalent to::
+
+      def filterfalse(predicate, iterable):
+          # filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
+          if predicate is None:
+              predicate = bool
+          for x in iterable:
+              if not predicate(x):
+                  yield x
+
 
 .. function:: groupby(iterable[, key])
 
@@ -298,21 +312,6 @@
                   self.currkey = self.keyfunc(self.currvalue)
 
 
-.. function:: filterfalse(predicate, iterable)
-
-   Make an iterator that filters elements from iterable returning only those for
-   which the predicate is ``False``. If *predicate* is ``None``, return the items
-   that are false. Equivalent to::
-
-      def filterfalse(predicate, iterable):
-          # filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
-          if predicate is None:
-              predicate = bool
-          for x in iterable:
-              if not predicate(x):
-                  yield x
-
-
 .. function:: islice(iterable, [start,] stop [, step])
 
    Make an iterator that returns selected elements from the iterable. If *start* is
@@ -342,30 +341,6 @@
    then the step defaults to one.
 
 
-.. function:: zip_longest(*iterables[, fillvalue])
-
-   Make an iterator that aggregates elements from each of the iterables. If the
-   iterables are of uneven length, missing values are filled-in with *fillvalue*.
-   Iteration continues until the longest iterable is exhausted.  Equivalent to::
-
-      def zip_longest(*args, fillvalue=None):
-          # zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
-          def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
-              yield counter()         # yields the fillvalue, or raises IndexError
-          fillers = repeat(fillvalue)
-          iters = [chain(it, sentinel(), fillers) for it in args]
-          try:
-              for tup in zip(*iters):
-                  yield tup
-          except IndexError:
-              pass
-
-   If one of the iterables is potentially infinite, then the :func:`zip_longest`
-   function should be wrapped with something that limits the number of calls
-   (for example :func:`islice` or :func:`takewhile`).  If not specified,
-   *fillvalue* defaults to ``None``.
-
-
 .. function:: permutations(iterable[, r])
 
    Return successive *r* length permutations of elements in the *iterable*.
@@ -525,6 +500,30 @@
    is faster to use :func:`list` instead of :func:`tee`.
 
 
+.. function:: zip_longest(*iterables[, fillvalue])
+
+   Make an iterator that aggregates elements from each of the iterables. If the
+   iterables are of uneven length, missing values are filled-in with *fillvalue*.
+   Iteration continues until the longest iterable is exhausted.  Equivalent to::
+
+      def zip_longest(*args, fillvalue=None):
+          # zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
+          def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
+              yield counter()         # yields the fillvalue, or raises IndexError
+          fillers = repeat(fillvalue)
+          iters = [chain(it, sentinel(), fillers) for it in args]
+          try:
+              for tup in zip(*iters):
+                  yield tup
+          except IndexError:
+              pass
+
+   If one of the iterables is potentially infinite, then the :func:`zip_longest`
+   function should be wrapped with something that limits the number of calls
+   (for example :func:`islice` or :func:`takewhile`).  If not specified,
+   *fillvalue* defaults to ``None``.
+
+
 .. _itertools-example:
 
 Examples


More information about the Python-checkins mailing list