I have two lists. They have the same size and kind of related to each other. I wanna make one of them unique and eliminate the corresponding element in the other list. (So I need the index of eliminated item).Suppose we always keep the first one and eliminate the other identical items.
Example:
my_list=[['A','B','C'],['D','Q'],['O','W','S'],['D','Q'],['D','Q']]
sec_list=[[1,2,5],[3,4],[5,6,4],[7,8],[2,5]]
The result:
my_list=[['A','B','C'],['D','Q'],['O','W','S]]
sec_list=[[1,2,5],[3,4],[5,6,4]]
What I did:
I know how to make elements of a list unique by the following code:
Uni=[]
[Uni.append(i) for i in my_list if i not in Uni]
But it doesn't give me the index to delete corresponding items in the second list. I tried for loop:
index_remove=[]
for s,i in enumerate(my_list):
for r,j in enumerate(my_list):
if s!=r:
if i==j:
if s not in index_remove:
index_remove.append(s)
But it gives me the index of all similar items. Not the one that should be removed.