Popular recipes by Jon Dyte http://code.activestate.com/recipes/users/99939/2002-06-05T09:45:38-07:00ActiveState Code RecipesPredicate tests across sequences (Python)
2002-06-05T09:45:38-07:00Jon Dytehttp://code.activestate.com/recipes/users/99939/http://code.activestate.com/recipes/52907-predicate-tests-across-sequences/
<p style="color: grey">
Python
recipe 52907
by <a href="/recipes/users/99939/">Jon Dyte</a>
.
Revision 2.
</p>
<p>Often it is useful to know whether all elements of sequence meet
certain criteria, or if only some pass a test.
These two functions "every" and "any" do just that.</p>
<p>Example usage:</p>
<pre class="prettyprint"><code>>>> every(lambda c: c > 5,(6,7,8,9))
1
>>> every(lambda c: c < 5,(6,7,8,9))
0
>>> any(lambda c: c > 5,(6,7,8,9))
1
>>> any(lambda c: c < 5,(6,7,8,9))
0
</code></pre>