Assuming you have any old_list
with a list of index pos
that you want to get rid of:
new_list = [old_list[i] for i, e in enumerate(old_list) if i not in pos]
This will work for both the list in your question by getting rid of the element at index specified by pos
, just substitute old_list
with list name you currently have:
dS = [0, 0.02, 0, 0.04, 0.07, 0]
dN = [1, 0.02, 0.3, 0.7, 0.9]
pos = [i for i, e in enumerate(dS) if e ==0]
dS = [dS[i] for i, e in enumerate(dS) if i not in pos]
dN = [dN[i] for i, e in enumerate(dN) if i not in pos]
>>> dS, dN
([0.02, 0.04, 0.07], [0.02, 0.7, 0.9])
This work fine for list which lengths are different, as shown in your case above.