I'm writing a method that takes a list of lists ([[], [], [],], for example), and weeds out all lists that already have an existing permutation in the main list.
For example, if given: [[1, 2, 3, 4], [2, 3, 4, 1], [1, 2, 4, 3]], it would only return [[1, 2, 3, 4]].
Or, if given: [[0, 0, 1, 1], [1, 1, 0, 0], [0, 1, 1, 0], it would only return [0, 0, 1, 1]].
The edge case is if I give it a list like: [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ,[0, 0, 0, 0]], it returns [[0, 0, 0, 0], [0, 0, 0, 0]]
This is because the second for loop in my method is ending early, and I can't figure out why. Thanks so much in advance!
def removeDuplicates(self, lists):
for list in lists:
list.sort()
returnList = lists
for list in lists:
returnList.remove(list)
if not list in returnList:
returnList.append(list)
return returnList