Remove duplicates of first elements of pairs
-
04-11-2019 - |
Question
A list of pairs is given using Python. I want to remove duplicate occurrences of the first element of the pair leaving only one occurrence of each first element paired with the highest second element it comes with. I am looking for an efficient solution that returns the pairs sorted.
>>> myfunc([[2, 0], [3, 0], [4, 0], [5, 0], [3, 2], [4, 0], [5, 3], [5, 3]])
[[2, 0], [3, 2], [4, 0], [5, 3]]
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange