Skip to main content
Tweeted twitter.com/#!/StackMma/status/519749964688142336
added 18 characters in body
Source Link
Karsten7
  • 27.6k
  • 5
  • 74
  • 135

I'm trying to sort a list of lists. The sublists are defined in length, but the length of the list containing it varies.

A simplified set might be: {{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}} but

{{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}}

but it could be: a={{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}, {12, 4, 8}}

a={{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}, {12, 4, 8}}

Sorting on the last element is built-in using

SortBy[a,Last];

SortBy[a,Last];

How do I sort on an arbitrary element? In the example, the second.

I'm trying to sort a list of lists. The sublists are defined in length, but the length of the list containing it varies.

A simplified set might be: {{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}} but it could be: a={{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}, {12, 4, 8}}

Sorting on the last element is built-in using

SortBy[a,Last];

How do I sort on an arbitrary element? In the example, the second.

I'm trying to sort a list of lists. The sublists are defined in length, but the length of the list containing it varies.

A simplified set might be:

{{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}}

but it could be:

a={{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}, {12, 4, 8}}

Sorting on the last element is built-in using

SortBy[a,Last];

How do I sort on an arbitrary element? In the example, the second.

Source Link
Rick R
  • 407
  • 2
  • 10

Sorting Lists of lists of arbitrary length

I'm trying to sort a list of lists. The sublists are defined in length, but the length of the list containing it varies.

A simplified set might be: {{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}} but it could be: a={{1, 2, 3}, {7, 1, 4}, {3, 5, 6}, {10, 7, 1}, {12, 4, 8}}

Sorting on the last element is built-in using

SortBy[a,Last];

How do I sort on an arbitrary element? In the example, the second.