Re: [Python-Dev] collections.Counter __add__ implementation quirk

2015-11-24 Thread Michael Selik
Raymond, I think you made a typographical error in your Counter.update example. >>> from collections import Counter >>> c = Counter(a=4, b=2, c=0, d=-2) >>> d = Counter(a=1, b=-5, c=-2, d=6) >>> c.update(d) >>> c Counter({'a': 5, 'd': 4, 'c': -2, 'b': -3}) Pair programming

Re: [Python-Dev] collections.Counter __add__ implementation quirk

2015-11-23 Thread Raymond Hettinger
> On Nov 23, 2015, at 10:43 AM, Vlastimil Brom wrote: > >> 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.

Re: [Python-Dev] collections.Counter __add__ implementation quirk

2015-11-23 Thread Vlastimil Brom
2015-11-23 7:21 GMT+01:00 Alexander Walters : > 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 th

[Python-Dev] collections.Counter __add__ implementation quirk

2015-11-22 Thread Alexander Walters
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..