5
$\begingroup$

I have the list:

a = {{1.0, 3.0}, {4.0, 3.0}, {1.0, 4.0}, {4.0, 1.5}, {1.2, 4.0}, {2., 
   8.}, {9.0, 9.0}};

When I apply SortBy[a,Last] I get the following:

{{4., 1.5}, {1., 3.}, {4., 3.}, {1., 4.}, {1.2, 4.}, {2., 8.}, {9., 
  9.}}

My question: For those with similar Last part, How can I order them from Largest to smallest, so the final output would look like:

{{4., 1.5}, {4., 3.}, {1., 3.}, {1.2, 4.}, {1., 4.}, {2., 8.}, {9., 
  9.}}

Thanks

$\endgroup$
0

1 Answer 1

9
$\begingroup$

You could use something like:

SortBy[a, {Last, Minus@*First}]

{{4., 1.5}, {4., 3.}, {1., 3.}, {1.2, 4.}, {1., 4.}, {2., 8.}, {9., 9.}}

$\endgroup$
1
  • $\begingroup$ Many thanks Carl. A great helper here. $\endgroup$
    – qahtah
    Commented Dec 17, 2017 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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