collections.Counter.__add__ as a bit of a quirk.

Counters allow for negative numbers. You can subtract from a counter into the negative no problem. However, if you have a counter with a negative value and add it to another counter, and if that value, after addition, would still be negative... that value is not included in the resulting Counter object. This is kind of weird, to the point of thinking I had a bug in other code for several hours until I went and checked how Counters are implemented.

Is there any particular reason counters drop negative values when you add them together? I definitely expected them to act like ints do when you add negatives, and had to subclass it to get what I think is the obvious behavior.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to