Suppose I have an object of the structure:
class Obj:
def match(other):
return check_match(self, other)
For example, check_match
could check for overlap or for equality or for "is friend".
Now I'll have a list of those objects:
objList = create_random_list_of_Obj()
Now, for each element which matches other elements, I d like to keep only one of those mutually matching elements.
Remark and clarification: So far, the task is ambiguous: If A and B match, and B and C match, but A and C do not match, then we could keep A and C or we could keep B. It's not important, which decision the algorithm will take. The important thing is, that there are no matching elements in the final list.
Two questions:
- What is the pythonic way to do so?
- Does this problem have a name?