Message229065
> 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. |
|
Date |
User |
Action |
Args |
2014-10-11 07:37:32 | rhettinger | set | recipients:
+ rhettinger, mark.dickinson, pitrou, scoder, eric.smith, steven.daprano, r.david.murray, cool-RR, ethan.furman, serhiy.storchaka, Saimadhav.Heblikar, josh.r |
2014-10-11 07:37:32 | rhettinger | set | messageid: <1413013052.42.0.0161958102107.issue22515@psf.upfronthosting.co.za> |
2014-10-11 07:37:32 | rhettinger | link | issue22515 messages |
2014-10-11 07:37:31 | rhettinger | create | |
|