Document another recipe for itertools: all_equal(). Inspired by David Beazley.
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index ea279b0..a48f692 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -695,6 +695,11 @@
"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(imap(pred, iterable))