I have a List which contains equal-length-sequences (In this example the length of the sequences is 2, but it can be longer than that in other cases) of numbers, for example:
[[3, 2], [0, 6], [6, 0], [7, 7], [0, 5], [7, 7]]
Now I want to remove all duplicates ([7, 7]
appears twice) but also remove all reverse duplicates ([0, 6]
and [6, 0]
).
My current code is this:
def getUniqueShapes(shapes):
unique = []
for shape in shapes:
if shape not in unique and reversed(shape) not in unique:
shapes.append(shape)
print(unique)
My expected output for this example is
[[3, 2], [0, 6], [7, 7], [0, 5]]
Because of the not in
, this algorithm runs with very poor speed.
Is there an easy way I can apply such a condition to the list with a better time complexity?