I have something like:
a = [4,3,1,6,3,5,3]
b = [4,2,6]
and I wanted to remove the 3 elements of b from a. I was trying to do:
c = a - b
but I was thinking that the inverse of merge (+
) might not be a thing, and was correct: Unsupported Operand types for -: list and list. I was contemplating just looping over them, but that just doesnt really sound pythony.
My end state is going to be: c = [3,1,3,5,3]
If you had not noticed, b is not a subset of a and these are unordered. 2 different sets, these sets are not unique either, but only want to remove 1 instance per i in b
, not all instance of i in b
EDIT It seems that the current answer does not resolve my question.
a = [1,1,2,2,2,3,4,5]
b = [1,3]
c = [x for x in a if x not in b]
#c result is [2,2,2,4,5]
I want c to return: [1,2,2,2,4,5]
For the sake of speed typing, I just put sorted numbers, but the lists ARE IN FACT unsorted, though for the sake of cleanliness we can sort them.
They are just unsorted at init. Since there are duplicates in list items, I can't use a set as per the definition of set.