title: What is a good way to do countif in Python
body: <p>I want to count how many members of an iterable meet a given condition. I'd like to do it in a way that is clear and simple and preferably reasonably optimal.</p>
  
  <p>My current best ideas are:</p>
  
  <pre><code>sum(meets_condition(x) for x in my_list)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>len([x for x in my_list if meets_condition(x)])
  </code></pre>
  
  <p>The first one being iterator based is presumably faster for big lists. And it's the same form as you'd use for testing any and all. However it depends on the fact that int(True) == 1, which is somewhat ugly.</p>
  
  <p>The second one seems easier to read to me, but it is different from the any and all forms.</p>
  
  <p>Does anyone have any better suggestions? is there a library function somewhere that I am missing?</p>