I have a dictionary and a list as given below
correction = {u'drug.ind': u'Necrosis', "date": "exp"}
drugs = [[u'drug.aus', u'Necrosis'], [u'drug.nz', u'Necrosis'], [u'drug.uk', u'Necrosis'], [u'drug.ind', u'Necrosis'], [u'cheapest', u'drug.ind'], [u'date', u'']]
Now basically I look at the correction dictionary value and whenever it matches for every second element of the lists in drugs
list, I remove them.
This is what I do
if correction and drugs:
for i,x in correction.items():
for j,k in enumerate(drugs):
if len(i.split(".")) > 1: # need to do the operation only for drugs which is always given in this format
if x == k[1]:
drugs.pop(j)
Ideally the drugs
list should now look like
drugs = [['cheapest', 'drug.ind'], ['date', '']]
But for some reason it looks like
[['drug.nz', 'Necrosis'], ['drug.ind', 'Necrosis'], ['cheapest', 'drug.ind'], ['date', '']]
I was hoping that everything that looks like Necrosis will be removed. But it removes it alternatively.
Why do I encounter this behaviour? What am I doing wrong?