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

Vedran Čačić report at bugs.python.org
Thu May 17 16:02:08 EDT 2018


Vedran Čačić <vedgar at gmail.com> added the comment:

As I said above, if we're going to go down that route, it seems much more reasonable to me that total should be a cached property, that's updated on every Counter update (in __setitem__, increased by a difference of a new value and an old one for that key).

And normalization should just provide a view over the Counter, that just passes the values through division with the above cached property. The view should of course be immutable by itself, but should reflect the changes of the underlying counter, just as already existing views (e.g. dict_values) do.

----------

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


More information about the Python-bugs-list mailing list