I need a data type like bag / multiset in Python. I understand the collection. Often used for this purpose. But comparison operators don't seem to work:
In [1]: from collections import Counter
In [2]: bag1 = Counter(a=1, b=2, c=3)
In [3]: bag2 = Counter(a=2, b=2)
In [4]: bag1 > bag2
Out[4]: True
This seems like a mistake to me. I expected operators with fewer and greater numbers than operators to perform subset and supernet mappings. But if this is so, then it bag1 > bag2will be false, because it bag2contains an additional one 'a'. There are also no subset / superset methods on Counter objects. Therefore, I have two questions:
- What comparison scheme is used for Counter objects?
- How to compare Counter objects for a subset, subset, the correct subset, and your own superset?