How to check if every element of a list satisfies a condition in Python

Each element in a list can be checked against a given condition. For example, checking whether each element in [1, 2, 3] is greater than 0 returns True.

Solution for How to check if every element of a list satisfies a condition in Python : You can use all() to check if every element of a list satisfies a condition Use the syntax condition for item in list to build a generator expression that checks each item in list against a given condition. Call all(generator) with the generator expression as generator to return True if every element in the list satisfies the condition and False otherwise.


how-to-check-if-every-element-of-a-list-satisfies-a-condition-in-python