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$
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.}}

| improve this answer | |
$\endgroup$
  • $\begingroup$ Many thanks Carl. A great helper here. $\endgroup$ – qahtah Dec 17 '17 at 21:21

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.