How to find elements in a list satisfying different criteria
One approach goes like this:
First /@ GatherBy[list1, Last]
It turns out that GatherBy
can be replaced by SplitBy
.
You can also use SequenceReplace
:
SequenceReplace[list1, {p : ({_, a_} ..)} :> First[{p}]]
{{3, 2}, {7, 4}, {12, 8}, {4, 10}}
This seems to work.
DeleteDuplicatesBy[list1, Last]
{{3, 2}, {7, 4}, {12, 8}, {4, 10}}