[issue14182] collections.Counter equality test thrown-off by zero counts

Mark Dickinson report at bugs.python.org
Tue Aug 7 09:15:26 CEST 2012


Mark Dickinson added the comment:

> Raymond, Stephen's analysis seems correct.  Are we missing something or
> can this issue be closed?

Well, depending on how you think about Counters, the current behaviour of equality definitely leads to some surprises.  For example:

>>> Counter(a = 3) + Counter(b = 0) == Counter(a = 3, b = 0)
False

OTOH, if we're consistent about regarding a count of 0 as 'equivalent' to a missing element, then __nonzero__ / __bool__ probably needs changing, too.

>>> c = Counter(a = 0)
>>> bool(c)
True
>>> bool(c + c)
False

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14182>
_______________________________________


More information about the Python-bugs-list mailing list