<div dir="ltr"><div class="gmail_quote">On Wed, Apr 6, 2011 at 1:54 AM, Raymond Hettinger <span dir="ltr"><<a href="mailto:raymond.hettinger@gmail.com">raymond.hettinger@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Apr 5, 2011, at 2:16 PM, cool-RR wrote:<br>
<br>
> Hello folks,<br>
><br>
> I noticed today that bool(Counter({'a': 0'})) is True.<br>
><br>
> Is this wise? I want to be able to do:<br>
><br>
>     if my_counter:<br>
>         whatever<br>
<br>
</div>As explained on tracker where you made the same request,<br>
that counter is not an empty container.  Accordingly, it's bool<br>
value is True.  The python language has been consistent<br>
with this for a long time (as I found-out years ago when<br>
I proposed putting a __len__ attribute on various iterools<br>
when the output iterator length was known, but Guido<br>
wanted the iterator to always have a bool value of False).<br>
<br>
A Counter object is essentially just a dictionary with a<br>
__missing__ method to supply an implied zero default count.<br>
Accordingly, it needs to behave as much like a dictionary<br>
as possible.<br>
<font color="#888888"><br>
<br>
Raymond<br></font></blockquote><div><br></div><div>Okay, this argument applies against `Counter.__bool__`, but not against `Counter.elements().__bool__`. So I want to hear whether people would find a  `Counter.elements().__bool__` method useful.</div>
<div><br></div><div><br></div><div>Ram.</div></div>
</div>