Reputation: 45
I want to write a function:
def CheckBoolean(lst):
if the list only contains True or False, it will return True, otherwise it will return False
Upvotes: 0
Views: 1092
Reputation: 6234
You can use Python built-in function all
for this.
result = all(isinstance(item, bool) for item in last)
all
returnTrue
if all elements of the iterable are true (or if the iterable is empty).
Upvotes: 2
Reputation: 88
def CheckBoolean(lst):
return all(isinstance(i, bool) for i in lst)
Upvotes: 1