removing multiple values from lists gets tricky since the position of values in a list changes as the list gets smaller and smaller. It is better to regenerate what you want from what you have and don't want.
A small example...and one of many, many, many options is as follows.
- load, compile and run the script below
- change the data and omit variables to experiment
- implement on your own data and data structure
def remove_vals(data,omit):
as_set = set(data)
out_lst = [ x for x in data if x not in omit]
return out_lst
if __name__=="__main__":
"""change below to suit"""
data = ["a", "d","e","b","c","a","a","a","b","a","c"]
omit = ["a","e"]
returned = remove_vals(data,omit)
frmt = "\nInputs...{}\nTo remove...{}\nOutputs...{}"
print(frmt.format(data,omit,returned))
The results from the above run are as follows.
>>>
Inputs...['a', 'd', 'e', 'b', 'c', 'a', 'a', 'a', 'b', 'a', 'c']
To remove...['a', 'e']
Outputs...['d', 'b', 'c', 'b', 'c']
Now don't try to copy this code exactly on your problem...emulate and consider what you have, what you want, then go for a solution