I am facing the following problem. I have multiple lists in Python that I want them to have them sorted with a sort of indexing in order to remove items from the other lists. Let me further explain.
listA_ID = [1,2,3,5,6,7] # integer from 0-250
listA_Var1 = [3.9, 4.7, 2.1, 1.2, 0.15, 0.99]
listB_ID = [2,5,6,7,8,10] # integer from 0-250
listB_Var1 = [0.54, 0.35, 1.19, 2.45, 3.1, 1.75]
>> After Comparison of listA_ID & listB_ID I should end up with the common IDs.
listA_ID = listB_ID = sorted(list(set(listA_ID) & set(listB_ID)))
listA_ID = [2,5,6,7]
listB_ID = [2,5,6,7]
Therefore I want to delete the elements [1, 3] from listA_ID which are in the positions of [0, 2] of that list and the same thing from listA_Var1, delete [3.9, 2.1] which are in the same positions [0, 2].
Similarly, I want to remove the elements [8, 10] from listB_ID which are in the positions of [4, 5] of that list and the same thing from listB_Var1, delete [3.1, 1.75] which are in the same positions [4, 5].
>> and then listA_Var1 & listB_Var1 will become
listA_Var1 = [4.7, 1.2, 0.15, 0.99]
listB_Var1 = [0.54, 0.35, 1.19, 2.45]
Any ideas on an efficient way to implement that? From my experience using Matlab a lot, after comparing the two lists, I have a way to get the indexes that are not needed and then applying these indexes to the lists, what I get are the final lists listA_Var1 & listB_Var1.
Any ideas please? Thanks in advance!