[issue22515] Implement partial order on Counter

Steven D'Aprano report at bugs.python.org
Sat Oct 4 12:13:25 CEST 2014


Steven D'Aprano added the comment:

On Sat, Oct 04, 2014 at 08:38:17AM +0000, Ram Rachum wrote:
> 
> Ram Rachum added the comment:
> 
> > There are some properties of set comparison:
> > 
> > (a < b) == (a <= b and a != b)
> 
> I don't think so, because counter equality is based on dict equality so it doesn't ignore zero values.

That's a very good point! That suggests that we shouldn't treat Counters 
as multisets (a.k.a. bags) and define subset/superset operators. They're 
*almost* multisets, but not quite the same, since:

Counter({'a': 0}) != Counter({})

but the formal definition of multiset suggests those should be equal:

https://en.wikipedia.org/wiki/Multiset#Formal_definition

Perhaps we should rethink this. I'm starting to wonder whether we need a 
PEP to define exactly how subset and superset should be defined for 
Counters. This is precisely the trouble with rushing to add code before 
we know what the code is supposed to do... :-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22515>
_______________________________________


More information about the Python-bugs-list mailing list