Skip to main content
added 75 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176

To sort by a specific element use a pure function with the number in question. For your case (the second element) just do:

SortBy[a, #[[2]] &]
 {{7, 1, 4}, {1, 2, 3}, {12, 4, 8}, {3, 5, 6}, {10, 7, 1}}
    

You can also use Sort like this:

Sort[a, #1[[2]] < #2[[2]] &]

To sort by a specific element use a pure function with the number in question. For your case (the second element) just do:

SortBy[a, #[[2]] &]
 {{7, 1, 4}, {1, 2, 3}, {12, 4, 8}, {3, 5, 6}, {10, 7, 1}}
    

To sort by a specific element use a pure function with the number in question. For your case (the second element) just do:

SortBy[a, #[[2]] &]
 {{7, 1, 4}, {1, 2, 3}, {12, 4, 8}, {3, 5, 6}, {10, 7, 1}}
    

You can also use Sort like this:

Sort[a, #1[[2]] < #2[[2]] &]
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176

To sort by a specific element use a pure function with the number in question. For your case (the second element) just do:

SortBy[a, #[[2]] &]
 {{7, 1, 4}, {1, 2, 3}, {12, 4, 8}, {3, 5, 6}, {10, 7, 1}}