[issue22533] Counter with no keys does not compare equal to Counter with keys which zero value
Josh Rosenberg
report at bugs.python.org
Thu Oct 2 00:05:51 CEST 2014
Josh Rosenberg added the comment:
Reading the note on the Counter class (about intent vs. actual use), it looks like changing this behavior would involve potentially breaking a lot of code.
If you're using Counters that are intended to maintain positive counts (treating a count <= 0 as if the key does not exist), it seems like you could either perform your operations using the + and - (or += and -=) binary operators (which will remove keys when the values drop to 0 or below) or if you have to use subtract or manual count tweaking, normalize the Counters at comparison time, that is, use +counter1 == +counter2 (unary + support added in 3.3).
I agree it's sort of weird, but I feel like fixing it will just break a ton of existing code.
----------
nosy: +josh.rosenberg
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22533>
_______________________________________
More information about the Python-bugs-list
mailing list