Suppose I have two lists listBig and listSmall and I want to delete all elements of listSmall from listBig. Assume that all elements of listSmall are present in listBig and that if there are multiple instances of an element of listSmall in listBig, they must not be deleted, meaning deleting one is the key.
Is there a better way to achieve this than:
listBig = [1,2,3,4,5,6,7,8,4,7]
listSmall = [4,7]
deleted = 0
inner = 0
for outer in range(0,len(listSmall)):
while not deleted == len(listSmall):
if listSmall[outer]==listBig[inner]:
listBig.remove(listBig[inner])
inner=0
deleted+=1
break
inner+=1
print listBig
OUTPUT: [1, 2, 3, 5, 6, 8, 4, 7]