# extract replacement list with conditions

I have a long list of lists of values and replacement rules as:

list = {
{{0.5, {r0 -> 0.1, a -> 2.3}}, {2.0, {r0 -> 0.8, a -> 0.4}}, {1.2, {r0 -> 1.1, a -> 0.7}}}
{{4.2, {r0 -> 5.1, a -> 0.9}}, {0.1, {r0 -> 1.3, a -> 7.4}}, {1.0, {r0 -> 3.3, a -> 0.4}}}
{{1.0, {r0 -> 1.1, a -> 1.9}}, {0.7, {r0 -> 1.2, a -> 2.2}}, {0.1, {r0 -> 4.8, a -> 3.2}}}
(*AND SO ON till more than 1000 lists*)
}


I would like to make another list, with the second elements of the previous list, such that the first one is the minimum of the each row... I mean, something like

{ {r0 -> 0.1, a -> 2.3}
, {r0 -> 1.3, a -> 7.4}
, {r0 -> 4.8, a -> 3.2}
, (*...*)
}

• the minimum has to be the first element, not in the replacement list; in the last row is {0.1, {r0 -> 4.8, a -> 3.2}} Apr 25, 2017 at 12:16
• it worked great, thanks @Kuba Apr 25, 2017 at 13:27

Map[First@Cases[#, {x_ /; x == Min[First @@@ #[[All, 1]]], pat : __ } :>
pat , Infinity] &, list]


or in a more succint and better way proposed by Kuba:

Last@*First@*MinimalBy[First]/@ list


another method that works (suggested by pfactors):

Last@First@Sort@# &/@ list

• Probably worth noting Ali that your version (although probably slower) would work in MMA < 10. As a side note I think Last@First@Sort@# & /@ list might work as well. Apr 25, 2017 at 17:22

In:

Clear[a, r0, list]
list = {{{0.5, {r0 -> 0.1, a -> 2.3}}, {2.0, {r0 -> 0.8,
a -> 0.4}}, {1.2, {r0 -> 1.1, a -> 0.7}}}, {{4.2, {r0 -> 5.1,
a -> 0.9}}, {0.1, {r0 -> 1.3, a -> 7.4}}, {1.0, {r0 -> 3.3,
a -> 0.4}}}, {{1.0, {r0 -> 1.1, a -> 1.9}}, {0.7, {r0 -> 1.2,
a -> 2.2}}, {0.1, {r0 -> 4.8, a -> 3.2}}}};

list // Map@MinimalBy@First // Last @@@ # &


Out:

{{r0 -> 0.1, a -> 2.3}, {r0 -> 1.3, a -> 7.4}, {r0 -> 4.8, a -> 3.2}}