0

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

1
  • 2
    Why are you enumerating? Commented Feb 15, 2021 at 4:34

2 Answers 2

2

You can use Python built-in function all for this.

result = all(isinstance(item, bool) for item in last)

all return True if all elements of the iterable are true (or if the iterable is empty).

Sign up to request clarification or add additional context in comments.

Comments

1
def CheckBoolean(lst):
    return all(isinstance(i, bool) for i in lst)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.