There is a quick way to check whether all the values in an iterable object are True or not in Python.
Let us suppose that we have the following list and we want to check whether all the values in it are True:
One way to check it would be to loop through all the elements and check whether any of the values is False. If it is False, then we can return False.
If we have gone all the way until the end of the list and haven’t reached any False element, we just return True.
Let us see this in the implementation:
Another faster way that can help us without having to do an iteration through every element is using the function all():
Here is the complete example:
It’s that simple, yes.
Surprisingly, not a lot of people know about it. That’s why it’s worth preaching more.
I hope you find this useful.