summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-01-27 04:42:48 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-01-27 04:42:48 (GMT)
commit749761e1a8c47665d1f0814d0b85144280003867 (patch)
tree1e5c7b0669ea896acf26ca029141139481dbdeca /Doc
parentd07d939c5ee312905cce50bf885e62d60e4e4a33 (diff)
downloadcpython-749761e1a8c47665d1f0814d0b85144280003867.zip
cpython-749761e1a8c47665d1f0814d0b85144280003867.tar.gz
cpython-749761e1a8c47665d1f0814d0b85144280003867.tar.bz2
Put functions back in alphabetical order.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/itertools.rst77
1 files changed, 38 insertions, 39 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index aba1e25..1470721 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -245,6 +245,20 @@ loops that truncate the stream.
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 @@ loops that truncate the stream.
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 @@ loops that truncate the stream.
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 @@ loops that truncate the stream.
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