我试图判断一个小列表是否包含另一个大列表中存在的所有数字
- 这应该返回True,因为列表1中的所有元素都已在列表2中
case 2:[9797196]
- 这应该返回False,因为list1有两个97,而list2只包含一个97
list1 = [97,97,196]
list2 = [97,97,99,101,103,196]
def isConsist(list1,list2):
check = False
# Iterate in the 1st list
for m in list1:
# Iterate in the 2nd list
for n in list2:
# if there is a match
if m == n:
check = True
list2.remove(n) // remove the found element
else:
check = False
return False
return check
check = isConsist(list1,list2)
print(check)
这是我的代码,但工作不正常
我的代码得到了false,因为当它判断第一个列表中的196时,它会将其与第二个列表中的99进行比较,然后返回false