Python: See if one set contains another entirely?

前端 未结 7 1685
长情又很酷
长情又很酷 2020-12-13 05:11

Is there a fast way to check if one set entirely contains another?

Something like:

>>>[1, 2, 3].containsAll([2, 1])
True

>>>[1, 2,         


        
7条回答
  •  死守一世寂寞
    2020-12-13 05:56

    For completeness: this is equivalent to issubset (although arguably a bit less explicit/readable):

    >>> set([1,2,3]) >= set([2,1])
    True
    >>> set([1,2,3]) >= set([3,5,9])
    False
    

提交回复
热议问题