1
$\begingroup$

I have a list of the form

{
{1, {3., ∞, ∞, ∞}},
{2, {1.,1., ∞, ∞}}, 
{3, {0.333333, 0.666667, ∞, ∞}}
}

and I would like to sort it by the minimal of the nested list inside each element, namely, Min[{1.,1., ∞, ∞}] etc. The result should be

{
{3, {0.333333, 0.666667, ∞, ∞}}
{2, {1.,1., ∞, ∞}}, 
{1, {3., ∞, ∞, ∞}},
}

I tried SortBy[x,Min[Last]] but the result is unexpected. Any help?

$\endgroup$
  • 2
    $\begingroup$ SortBy[lis, Min[Last]] works for me on V 12. Why did it not work for you? $\endgroup$ – Nasser Feb 15 at 21:18
  • $\begingroup$ @Nasser Not sure. It works in some cases but not in all cases. $\endgroup$ – water liu Feb 15 at 23:59
4
$\begingroup$
lst = {{1, {3., ∞, ∞, ∞}}, {2, {1., 1., ∞, ∞}}, {3, {0.333333, 0.666667, ∞, ∞}}};

You can use Min@*Last or Min[Last@#] &

SortBy[Min@*Last]@lst

{{3,{0.333333,0.666667,∞,∞}},{2,{1.,1.,∞,∞}},{1,{3.,∞,∞,∞}}}

or

SortBy[Min[Last@#] &]@lst

{{3,{0.333333,0.666667,∞,∞}},{2,{1.,1.,∞,∞}},{1,{3.,∞,∞,∞}}}

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.