# Sort a list in a descending order

Say we have a list:

{{1/2, -(Sqrt[3]/2)}, {1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/2}, {-1, 0}, {-(1/2), -(Sqrt[3]/2)}}


now we want to sort that list by looking at the second component of each sub list (call it y coordinate for ease), i.e. sort it s.t. y is in the descending order. So we'd get

{{1/2, Sqrt[3]/2},{-1/2, Sqrt[3]/2},{1,0},{-1,0},{1/2,-(Sqrt[3]/2)},{-1/2,-(Sqrt[3]/2)}}


And yeah, I should mention that if there are more than one sub lists with equal y, we would additionally (sub)sort them by descending x (first component in each of the sub lists).

I tried to use SortBy, in different forms, but I don't seem to be able to figure it out by myself. I'd appreciate any help.

• "I tried to use SortBy" What did you try, specifically? Feb 13, 2019 at 13:57
• Likely a duplicate of mathematica.stackexchange.com/q/2729/12 Feb 13, 2019 at 13:59
• Try SortBy[list, N[-Last[#]]&] instead. Feb 13, 2019 at 14:25
• You did not say what you tried originally. N[Last] is not a function, so it's not appropriate here. Use N@*Last or N[Last[#]]&. Feb 13, 2019 at 14:26
• @amator, if you've figured it out from the comments, you can answer your own question. Helps the silent majority of lurkers develop their knowledge too. Feb 13, 2019 at 14:51

Reverse[SortBy[list, N[Last[#]]&]].
• If you use SortBy, you might as well put a minus sign in front of the sorting function so you don't have to reverse the list after sorting it. Feb 13, 2019 at 16:13