3 ms·
Python actually has built in support for multisets, you use a set of frozensets >>> a = set( (frozenset((1,2)), frozenset((3,4)) ) ) >>> frozenset((2,1)) in a
by drexlspivey 4y ago
Python actually has built in support for multisets, you use a set of frozensets
>>> a = set( (frozenset((1,2)), frozenset((3,4)) ) )
>>> frozenset((2,1)) in a
True
- Someone 4y agoThat’s not a multiset, it’s a set containing tuples. A multiset (https://en.wikipedia.org/wiki/Multiset https://en.wikipedia.org/wiki/Multiset) allows you to add identical items multiple times. You would use that to, for example, store the knowledge that 6 can be written as 3+3, by using a multiset {3,3} instead of a tuple (3,3)