[issue25478] Consider adding a normalize() method to collections.Counter()

Mark Dickinson report at bugs.python.org
Fri May 18 03:40:17 EDT 2018


Mark Dickinson <dickinsm at gmail.com> added the comment:

The point is that if you cache the total and update on each operation, you end up with a total that depends not just on the current contents of the Counter, but also on the history of operations. That seems like a bad idea: you could have two Counters with exactly the same counts in them (so that they compare equal), but with different cached totals.

So if floats (or Decimal instances) are permitted as Counter values, your suggested caching approach is not viable.

Of course, if Counter values are restricted to be plain old integers then it's fine, but that's not the current state of affairs.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25478>
_______________________________________


More information about the Python-bugs-list mailing list