This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients joern, rhettinger, serhiy.storchaka
Date 2015-02-24.21:05:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <18038611.3B6GOZtQHu@raxxla>
In-reply-to <1424792959.07.0.167295152397.issue23509@psf.upfronthosting.co.za>
Content
> - in the given patch __add__ uses __iadd__, but __sub__ doesn't use
> __isub__, which seems a bit weird.

If Counters are positive (common case), then the result of addition is not 
less than both summands. a + b is a and may be additional elements from b.
In the case of substraction a - b can be less than a and may be much less than 
a. In this case it is cheaper to create empty Counter and copy only those 
elements from a that are not in b, than copy all a and then remove almost all 
elements.

Relative efficiency depends on input data, and for some input data implementing 
__sub__ via __isub__ can be more efficient.

> - is there place for a non multi-set centric "Stats" object which is like
> Counter but with + and - actually behaving without the (in my use cases of
> Counter often counter intuitive) "> 0" stuff? (pun intended ;) ) Counter
> feels like a sub-class of Stats with the added _keep_positive(self).

I'm sure there is such class in third-party modules. Counter wouldn't have 
much benefit from inheriting "Stats", because it would need to override almost 
all methods.
History
Date User Action Args
2015-02-24 21:05:37serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, joern
2015-02-24 21:05:37serhiy.storchakalinkissue23509 messages
2015-02-24 21:05:37serhiy.storchakacreate