Just curious to know if anyone knows of an inbuilt version of:
bool_list: List[bool] = # some non-empty list of booleans
result = all(bool_list) or not any(bool_list)
# What I'm looking for
result = allsame(bool_list)
Just curious to know if anyone knows of an inbuilt version of:
bool_list: List[bool] = # some non-empty list of booleans
result = all(bool_list) or not any(bool_list)
# What I'm looking for
result = allsame(bool_list)
Not a built-in but does exactly what you are looking for in an efficient way:
from itertools recipes:
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)