I'm dealing with a nested list that looks something like this.
mylist =[
["First", "Second", "Third"],
["First", "Second", "Third"],
...
]
The goal is to remove duplicate elements of mylist based on the following definition: An element is equal to another element if element1[0] == element2[0]
and element1[1] == element2[1]
. Basically, only the first two elements count, ignore the rest.
This doesn't seem terribly hard but I'm probably over complicating it and having trouble with it. I think I am close to a solution, which I'll post if it gets done and nobody has answered.
My main problems:
I really wish I could turn the list to a set like in more conventional cases--is there any way to give set a custom definition of equivalence? A lot of built-in methods don't work because of that and rewriting them is a bit painful as the indexing always gets screwed up somewhere.
You can make a class that stores the data and override
__eq__
:Of course, this won't do any good for sets, which use hashing. for that you have to override
__hash__
: