4

I have a list

m = {{a, 20}, {b, 10}, {c, 50}, {d, 5}, {e, 100}} 

and I want to apply Sort on this in descending order on numbers only so that it looks like this

m = {{e, 100}, {c, 50}, {a, 20}, {b, 10}, {d, 5}}

How do I do that?

rhermans
  • 36,518
  • 4
  • 57
  • 149

1 Answers1

10

Data

m = {{a, 20}, {b, 10}, {c, 50}, {d, 5} , {e, 100}}

Code

Reverse[SortBy[m, Last]]

or

SortBy[m, Minus@*Last]

or since Mathematica v12

ReverseSortBy[Last][m]
{{e, 100}, {c, 50}, {a, 20}, {b, 10}, {d, 5}}

Where @* stands for Composition

rhermans
  • 36,518
  • 4
  • 57
  • 149