I'm using python to try and remove items that intersection from another list. So below is what I have.
letter = ['a', 'a', 'i', 'd', 'e', 'i', 'a', 'b', 'b', 'c', 'o', 'g', 'a', 'f', 'f', 'i', 'g', 'i' ]
cons = ['b','c','d', 'f', 'g']
and what I want is to remove any letter in the cons list from the letter list but preserve everything else. So below is what I want to get.
letter = ['a', 'a', 'i', 'e', 'i', 'a', 'o', 'a', i', 'i' ]
Below is what I have tried so far but it's not working.
for i in letter[:]:
if i in cons:
letter.remove(i)
cons.remove(i)
and...
list(set(x) - set(y))
I just want to remove the intersection of the lists and keep the duplicates from the first list that are not in the second list. Everything I've tried so far has removed those duplicates from the first list that I want to keep. Any help is greatly appreciated!