I have two lists in python, they contain points, and I want to remove from BOTH lists any permutation that exists in both lists.
I tried writing the followiing code that fails:
for indexA, pointA in enumerate(listA):
for indexB, pointB in enumerate(listB):
if isPermutation(listA[indexA],listB[indexB]):
del listA[indexA]
del listB[indexB]
This of course would not work because the del
command creates a new list and the for loop will loose the reference to both lists (not to mention it takes O(n) to remove from a list in python).
There are various ways to do this when you have one list which are mentioned here. But they don't seem to be helpful when working with two lists with the dependency above.
Could anyone supply code/a way to do this?
I care about speed.
Note: Building the list using .append() is really slow due to the fact its amortized.