[issue43062] Non-integer values in collections.Counter

Raymond Hettinger report at bugs.python.org
Fri Jan 29 14:13:19 EST 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

Thanks for the report, but there isn't anything that can be done about this.  The core design concept for Counter was to be a regular dictionary augmented by a few capabilities that made it suitable for counting.  It isn't closed-off in any way.  On the plus side, that makes it versatile and make it fit well the other parts of the Python ecosystem that work with dictionaries.  On the minus, there is nothing to keep out data that doesn't make sense in the context of counting.

FWIW, there is a multiset package on PyPi that offers a closed-off implementation that has an internal dictionary that can only be accessed by methods that prevent negative counts or non-integer values.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list