Checking if all elements of a List of Lists are in another List of Lists Python

前端 未结 2 1517
南方客
南方客 2021-01-24 21:37

My question is, how do you check if all of the elements of a list of lists are in another list of lists? Or maybe better phrased, how do you check if one list of lists

2条回答
  •  孤独总比滥情好
    2021-01-24 22:01

    Convert your sublists to tuples, for example:

    In [2]: a = [[2,3],[5,6],[8,9]]
    
    In [3]: b = [[2,3],[5,6],[8,9], [10,11]]
    
    In [4]: set(tuple(x) for x in a).issubset(tuple(x) for x in b)
    Out[4]: True
    

提交回复
热议问题