mirror of
https://github.com/python/cpython.git
synced 2025-11-20 02:50:14 +00:00
Merge
This commit is contained in:
commit
20b3e72b8d
2 changed files with 13 additions and 0 deletions
|
|
@ -693,6 +693,11 @@ which incur interpreter overhead.
|
|||
"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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue