When should I use list.count(0), and how do I to discount the "False" item?
<p><code>a.count(0)</code> always returns 11, so what should I do to discount the <code>False</code> and return 10?</p>

<pre><code>a = ["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9]
</code></pre>

<p>Python 2.x interprets <code>False</code> as <code>0</code> and vice versa. AFAIK even <code>None</code> and <code>""</code> can be considered <code>False</code> in conditions. 
Redefine count as follows:  </p>

<pre><code>sum(1 for item in a if item == 0 and type(item) == int)
</code></pre>

<p>or (Thanks to <a href="http://stackoverflow.com/questions/39404581/when-use-list-count0-how-to-discount-false-item/39404665?noredirect=1#comment66136825_39404665">Kevin</a>, and <a href="http://stackoverflow.com/questions/39404581/when-use-list-count0-how-to-discount-false-item/39404665?noredirect=1#comment66142335_39404665">Bakuriu</a> for their comments): </p>

<pre><code>sum(1 for item in a if item == 0 and type(item) is type(0))
</code></pre>

<p>or as suggested by <a href="http://stackoverflow.com/users/793428/ozgur">ozgur</a> in comments (<strong>which is not recommended and is considered wrong</strong>, see <a href="http://stackoverflow.com/questions/39404581/when-use-list-count0-how-to-discount-false-item/39404665?noredirect=1#comment66136825_39404665">this</a>), simply:  </p>

<pre><code>sum(1 for item in a if item is 0)  
</code></pre>

<p>it <strong>may</strong> (<a href="http://stackoverflow.com/questions/306313/is-operator-behaves-unexpectedly-with-integers?noredirect=1&amp;lq=1">âisâ operator behaves unexpectedly with integers</a>) work for <em>small</em> primary types, but if your list contains objects, please consider what <code>is</code> operator does:  </p>

<p>From the documentation for the <a href="http://docs.python.org/2/reference/expressions.html#not-in" rel="nofollow"><code>is</code> operator</a>:</p>

<blockquote>
  <p>The operators <code>is</code> and <code>is not</code> test for object identity: <code>x is y</code> is true
  if and only if x and y are the same object.</p>
</blockquote>

<p>More information about <code>is</code> operator: <a href="http://stackoverflow.com/questions/13650293/understanding-pythons-is-operator">Understanding Python's "is" operator</a></p>

python list count boolean