How to check if all items in a list are there in another list?

前端 未结 6 1084
误落风尘
误落风尘 2020-11-27 20:08

I have two lists say

List1 = [\'a\',\'c\',\'c\']
List2 = [\'x\',\'b\',\'a\',\'x\',\'c\',\'y\',\'c\']

Now I want to find out if all element

6条回答
  •  情书的邮戳
    2020-11-27 20:58

    This will return true is all the items in List1 are in List2

    def list1InList2(list1, list2):
        for item in list1:
            if item not in list2:
                return False
        return True
    

提交回复
热议问题