summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_itertools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-03-07 02:12:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-03-07 02:12:08 (GMT)
commit20b3e72b8df89aedcbaa17c4920da2f670ee1d84 (patch)
tree7ce74b04d7487946984342be4f37f15f521fd8cd /Lib/test/test_itertools.py
parenta2998a63c8951ab8254b96860fe64dcaa215eb1f (diff)
parente525ee3b483889313b62b09b4c9103d18dd9cbb7 (diff)
downloadcpython-20b3e72b8df89aedcbaa17c4920da2f670ee1d84.zip
cpython-20b3e72b8df89aedcbaa17c4920da2f670ee1d84.tar.gz
cpython-20b3e72b8df89aedcbaa17c4920da2f670ee1d84.tar.bz2
Merge
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r--Lib/test/test_itertools.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index fab9b31..5088b54 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -2064,6 +2064,11 @@ Samuele
... "Returns the nth item or a default value"
... return next(islice(iterable, n, None), default)
+>>> def all_equal(iterable):
+... "Returns True if all the elements are equal to each other"
+... g = groupby(iterable)
+... return next(g, True) and not next(g, False)
+
>>> def quantify(iterable, pred=bool):
... "Count how many times the predicate is true"
... return sum(map(pred, iterable))
@@ -2177,6 +2182,9 @@ perform as purported.
>>> nth('abcde', 9) is None
True
+>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
+[True, True, True, False, False]
+
>>> quantify(range(99), lambda x: x%2==0)
50