[Python-ideas] A meaningful `if counter:`
Bruce Leban
bruce at leapyear.org
Wed Apr 6 15:57:50 CEST 2011
No it won't.
>>> c = Counter()
>>> c[0] = 1
>>> c[None] = 2
>>> c[''] = 3
>>> list(c.elements())
[0, '', '', '', None, None]
>>> any(c.elements())
False # FAIL
>>> any(True for i in c.elements())
True
>>> d = Counter()
>>> any(True for i in d.elements())
False
--- Bruce
*New! *Puzzazz newsletter: http://j.mp/puzzazz-news-2011-04 including April
Fools!
*New!** *Blog post:
http://www.vroospeak.com/2011/04/march-gets-more-madness-next-year.html April
Fools!
On Wed, Apr 6, 2011 at 1:00 AM, cool-RR <cool-rr at cool-rr.com> wrote:
> On Wed, Apr 6, 2011 at 9:57 AM, Raymond Hettinger <
> raymond.hettinger at gmail.com> wrote:
>
>>
>> On Apr 5, 2011, at 11:59 PM, cool-RR wrote:
>>
>> > 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.
>> >
>>
>>
>>
>> if any(c.elements()):
>> ...
>>
>>
>> Raymond
>>
>
>
> Cool, this will be good enough.
>
>
> Ram.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110406/bc4ebeff/attachment.html>
More information about the Python-ideas
mailing list