# Mathematica edit list elements

I wanted to delete pair with the same argument and leave the pair with the lowest value, for example we have list:

data={{0.1, 1},{0.2, 15},{0.1, 7},{0.1, 11},{0.3, 27}};


And I want to get:

data={{0.1, 1},{0.2, 15},{0.3, 27}};


data = {{0.1, 1}, {0.2, 15}, {0.1, 7}, {0.1, 11}, {0.3, 27}};

First /@ GatherBy[SortBy[data, First], First]


{{0.1, 1}, {0.2, 15}, {0.3, 27}}

f = DeleteDuplicatesBy @ First @* Sort;

f @ data

{{0.1, 1}, {0.2, 15}, {0.3, 27}}

data = {{0.1, 1}, {0.2, 15}, {0.1, 7}, {0.1, 11}, {0.3, 27}};

MinimalBy[#, First, 1] & /* First /@ GatherBy[data, First]

(* {{0.1, 1}, {0.2, 15}, {0.3, 27}} *)

data = {{0.1, 1}, {0.2, 15}, {0.1, 7}, {0.1, 11}, {0.3, 27}};


Using Merge and MapApply (new in 13.1)

Merge[Min] @ MapApply[Rule] @ data


<|0.1 -> 1, 0.2 -> 15, 0.3 -> 27|>

KeyValueMap[List][%]


{{0.1, 1}, {0.2, 15}, {0.3, 27}}

data = {{0.1, 1}, {0.2, 15}, {0.1, 7}, {0.1, 11}, {0.3, 27}};


Using the third argument of GroupBy:

Values@GroupBy[data, First, First]

(*{{0.1, 1}, {0.2, 15}, {0.3, 27}}*)