list A: ['abc.txt', '123.txt', 'apple.jpg']
list B: ['ab', '123']
I want to generate a new list A that only contains the ones not in list B with wildcard match. The idea output will be:
list C: ['apple.jpg']
Here is my code:
lista=['abc.txt', 'happy.txt', 'apple.jpg']
listb=['happy', 'ab']
listc=lista
for a in lista:
for b in listb:
print(a + ": " + b)
if b in a:
listc.remove(a)
print(listc)
The output of my code is:
abc.txt: happy
abc.txt: ab
apple.jpg: happy
apple.jpg: ab
['happy.txt', 'apple.jpg']
Anyone know where it went wrong? And, any better way to do it? Tks.