I’m looking for a Python function similar to nubBy in Haskell, which removes duplicate but with a different equality test.
The function would take the equality test and the list as parameters, and would return the list of elements with no duplicates.
Example:
In [1]: remove(lambda x, y: x+y == 12, [2, 3, 6, 9, 10])
Out[1]: [2,3,6]
For example, here (2 and 10) and (9 and 3) are duplicates. I don’t care if the output is [10, 9, 6] or [2, 3, 6].
Is there an equivalent built-in function in Python? If not, what is the best way to efficiently implement it?
There is no built-in method (as the use case is rather esoteric), but you can easily write one:
Now, in the console: