Re: [Python-ideas] Counter comparison
On 2014-11-22 01:36, Antony Lee wrote:
I guess it depends on whether you think {"a": 1} < {"a": 2, "b": -1} or not. I actually thought about it and initially decided that the inequality should hold, but given that most_common works fine with negative counts, perhaps it shouldn't, indeed.
The other point is that if the 'b' entry was in the first, then it would be checked, and the negative count would matter, but as it wasn't, it won't, and it won't.
2014-11-21 16:27 GMT-08:00 MRAB <python@mrabarnett.plus.com <mailto:python@mrabarnett.plus.com>>:
On 2014-11-21 23:55, Antony Lee wrote:
As Counter objects effectively behave like multi-sets, it seems reasonable to overload <, <=, >, >= as for set objects to check whether a Counter is a sub/super-set of another Counter:
c < d <===> all(c[k] < d[k] for k in c)
Thoughts?
More correctly, it would be:
all(c[k] < d[k] for k in set(c) | set(d))
participants (1)
-
MRAB