summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-08-07 05:36:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-08-07 05:36:53 (GMT)
commit08d01eedeff8db39bcc081aebed0bfd1ae54e9e0 (patch)
tree1009941ccd93dc51e89714f0e5a76a1b8522cd33 /Doc/library
parente9499aef0a28fda0d3c4bdc0eb9ae220390299ac (diff)
downloadcpython-08d01eedeff8db39bcc081aebed0bfd1ae54e9e0.zip
cpython-08d01eedeff8db39bcc081aebed0bfd1ae54e9e0.tar.gz
cpython-08d01eedeff8db39bcc081aebed0bfd1ae54e9e0.tar.bz2
Add partition recipe to itertools docs.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/itertools.rst6
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 8037bfe..cadd0f3 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -653,6 +653,12 @@ which incur interpreter overhead.
pending -= 1
nexts = cycle(islice(nexts, pending))
+ def partition(pred, iterable):
+ 'Use a predicate to partition entries into false entries and true entries'
+ # partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9
+ t1, t2 = tee(iterable)
+ return filterfalse(pred, t1), filter(pred, t2)
+
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)