How to check whether a list is subset of another list in Python

1 Answer

0 votes
def isSubset(lst1, lst2):
    size1 = len(lst1)
    size2 = len(lst2)
    # j;
    for i in range(size2):
        for j in range(size1):
            if lst2[i] == lst1[j]:
                break
        if j == size1:
            return False
    return True


lst1 = [ 5, 1, 8, 12, 40, 7, 9, 100 ]
lst2 = [ 8, 40, 9, 1 ]
 
if (isSubset(lst1, lst2)):
    print("yes");
else:
    print("no");

 
 
   
'''
run:
   
yes
   
'''

 



answered Dec 21, 2021 by avibootz
...