Test if set is a subset, considering the number (multiplicity) of each element in the set

前端 未结 5 1913
谎友^
谎友^ 2020-12-19 14:32

I know I can test if set1 is a subset of set2 with:

{\'a\',\'b\',\'c\'} <= {\'a\',\'b\',\'c\',\'d\',\'e\'} # True

But the following is a

5条回答
  •  再見小時候
    2020-12-19 14:51

    The short answer to your question is there is no set operation that does this, because the definition of a set does not provide those operations. IE defining the functionality you're looking for would make the data type not a set.

    Sets by definition have unique, unordered, members:

    >>> print {'a', 'a', 'b', 'c'}
    set(['a', 'c', 'b'])
    >>> {'a', 'a', 'b', 'c'} == {'a', 'b', 'c'}
    True
    

提交回复
热议问题