Raymond Hettinger added the comment:
> I suggest implementing `Counter.__lt__` which will be a
> partial order, similarly to `set.__lt__`.
This would be reasonable if the counter were a strict stand-alone multiset or
bag; however, the core design is much looser than that (supporting negative
counts for example).
It would be more accurate to think about the Counter as a dict that returns 0
for missing keys and has few extra methods that can be handy in the content of
counting things.
Accordingly, a partial ordering operator wouldn't be well-defined for some of
the intended use cases.
The addition of subset/superset operations was considered and rejected during
the original design phase (the omission was intentional). It is better to
leave this to the user to decide what they want to do and how they intend to do
so. After all, it is as easily to work with as a regular dict. You can access
it directly or subclass it to fit your own needs.
The starting point for this class (when first proposed and endorsed by Guido)
was:
class Counter(dict):
def __missing__(self, key):
return 0
That core idea is dirt simple and it is not hard to build your own variants if
the one in collections doesn't meet your needs.
----------
resolution: -> rejected
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22515>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com