So I have a list, let's say
a = [1, 2, 3, 4, 2, 1, 2, 4]
1 appears twice, 2 appears three times, 4 appears twice. Now I define
b = [4, 2, 2]
Now I want a new list, c, that has the entries of a that are not in b. I tried using list comprehension:
c = [x for x in a if x not in b]
However, this omits the entry if it is in b, rather than seeing how many of each entry are in b and removing that many from a.
c == [1, 3, 1]
I would want it to be
c == [1, 3, 1, 2, 4]
Can anyone provide some help?