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 Saimadhav.Heblikar, cool-RR, eric.smith, ethan.furman, josh.r, mark.dickinson, pitrou, r.david.murray, rhettinger, scoder, serhiy.storchaka, steven.daprano 2014-10-04.09:58:51 -1.0 Yes <20141004095842.GH19757@ando.pearwood.info> <1412409436.33.0.2695585317.issue22515@psf.upfronthosting.co.za>
Content
```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:

http://singularcontiguity.wordpress.com/2008/05/07/multiset-equality-and-submultisets/
http://singularcontiguity.wordpress.com/2008/04/28/multiset-membership/

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?