This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Saimadhav.Heblikar, cool-RR, eric.smith, ethan.furman, josh.r, mark.dickinson, pitrou, r.david.murray, rhettinger, scoder, serhiy.storchaka, steven.daprano
Date 2014-10-04.09:58:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In-reply-to <>
On Sat, Oct 04, 2014 at 07:57:16AM +0000, Serhiy Storchaka wrote:

> There are some properties of set comparison:
> (a < b) == (a <= b and a != b)
> (a <= b) == (a < b or a == b)
> (a <= b and b <= a) == (a == b)
> (a < b and b < a) == False
> (a <= b) == (a - b == set())
> if (a <= b and b <= c) then (a <= c)
> (a <= b and a <= c) == (a <= (b & c))
> (a <= c and b <= c) == ((a | b) <= c)
> Is this true for Counter?

I believe these are all true for multisets.

But Counter is not *just* a multiset (a.k.a. bag) since the "counts" are 
not limited to non-negative integers (the natural numbers).

py> C = Counter()
py> C['a'] = -3
py> C['b'] = 'spam'
py> C['c'] = 0.5
py> C
Counter({'c': 0.5, 'b': 'spam', 'a': -3})

I don't know of any standard definition for subset and superset for 
multisets like C above. I think that we should raise an exception in 
cases like that: TypeError for cases where any "count" is non-numeric, 
and ValueError for cases where any count is not a non-negative integer.

(Later, if somebody comes up with a sensible meaning for sub/superset of 
such a Counter, we can relax that restriction.)

Another issue: are missing elements treated as if they have count 0? 
E.g. what are these?

Counter({'a': 0, 'b': 1}) <= Counter({'a': 1, 'b': 1})
Counter({'a': 0, 'b': 1}) <= Counter({'b': 1})

According to these pages:

I would argue that they should both return True (based on the idea that 
the "support" of a multiset is the set of those elements with non-zero 
count). But I don't know how authoritative that blog is. (The author 
even mentions that he only has a passing familiarity with some aspects 
of multisets.)

Anyone familiar with Haskell? What does this bag class do?

This may also be helpful. Sets and bags in Z language:
Date User Action Args
2014-10-04 09:58:52steven.dapranosetrecipients: + steven.daprano, rhettinger, mark.dickinson, pitrou, scoder, eric.smith, r.david.murray, cool-RR, ethan.furman, serhiy.storchaka, Saimadhav.Heblikar, josh.r
2014-10-04 09:58:52steven.dapranolinkissue22515 messages
2014-10-04 09:58:51steven.dapranocreate