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>&gt;&gt;&gt; every(lambda c: c &gt; 5,(6,7,8,9)) 1 &gt;&gt;&gt; every(lambda c: c &lt; 5,(6,7,8,9)) 0 &gt;&gt;&gt; any(lambda c: c &gt; 5,(6,7,8,9)) 1 &gt;&gt;&gt; any(lambda c: c &lt; 5,(6,7,8,9)) 0 </code></pre>