DeleteCases depending on all elements
list = {{10, 5}, {20, 4}, {20, 3}, {10, 6}};
1. You can use the function Internal`ListMin
as follows:
- Internal`ListMin[-list]
{{20, 4}, {10, 6}}
2. You can also use DeleteDuplicates
:
DeleteDuplicates[ReverseSort@list, And @@ Thread[GreaterEqual[##]] &]
{{20, 4}, {10, 6}}
3. ... and SequenceReplace
:
SequenceReplace[Sort @ list,
{a__} /; (And @@ Thread[LessEqual[a]]) :> Last[{a}]]
{{10, 6}, {20, 4}}
You can sort the list into ascending order using plain old Sort
, and then Split
it into sublists where the second element is ascending. The Last
element of each such sublist will be the one you want to keep:
Last /@ Split[Sort[list], #1[[2]] <= #2[[2]] &]
(* {{10, 6}, {20, 4}} *)
If you need the operation to keep the remaining elements in their original order, you can sort again based on PositionIndex
.
SortBy[
Last /@ Split[Sort[list], #1[[2]] <= #2[[2]] &],
PositionIndex[list]]
(* {{20, 4}, {10, 6}} *)