Sort a list of lists by increasing order of elementsImplementing a function which generalizes the merging...
Why are examinees often not allowed to leave during the start and end of an exam?
Checkmate in 1 on a Tangled Board
I just started; should I accept a farewell lunch for a coworker I don't know?
Rear derailleur got caught in the spokes, what could be a root cause
Listen to my Story...Let us find the Unique Invisible Pan Digital Pair
How does the 'five minute adventuring day' affect class balance?
How does mmorpg store data?
Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?
Calculus, water poured into a cone: Why is the derivative non-linear?
Two palindromes are not enough
Subset of knight's move in chess.
What was the first science fiction or fantasy multiple choice book?
I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again
Customs and immigration on a USA-UK-Sweden flight itinerary
Would skyscrapers tip over if people fell sideways?
Equatorial oceanic river caused by tides
Does friction always oppose motion?
Why wasn't ASCII designed with a contiguous alphanumeric character order?
Installed software from source, how to say yum not to install it from package?
Why will we fail creating a self sustaining off world colony?
What election rules and voting rights are guaranteed by the US Constitution?
Does it make sense to (partially) create a conlang that you don't intend to actually use in the story?
What prevents a US state from colonizing a smaller state?
Why would Dementors torture a Death Eater if they are loyal to Voldemort?
Sort a list of lists by increasing order of elements
Implementing a function which generalizes the merging step in merge sortSort lists according to the order of anotherSorting a list with secondary criterionSorting lists element by elementHow to sort my list?Sorting Lists of lists of arbitrary lengthArrangement Order and Multiple Columns Sorting Order of Associations with Missing KeysSort using indicesInserting an integer into a sorted listSort a list in a descending order
$begingroup$
What is the quickest way to sort a list of lists of integers, such that the first sorting criterion is the first element of the list, the next is the second element of the list and so on?
E.g. The list
list = {{1,3,4,5}, {1,2,4,3}, {1,1,2,8}, {1,3,5,6}, {1,2,3,4}}
would under these rules be sorted to
sortedlist = {{1,1,2,8}, {1,2,3,4}, {1,2,4,3}, {1,3,4,5}, {1,3,5,6}}
list-manipulation sorting
$endgroup$
add a comment |
$begingroup$
What is the quickest way to sort a list of lists of integers, such that the first sorting criterion is the first element of the list, the next is the second element of the list and so on?
E.g. The list
list = {{1,3,4,5}, {1,2,4,3}, {1,1,2,8}, {1,3,5,6}, {1,2,3,4}}
would under these rules be sorted to
sortedlist = {{1,1,2,8}, {1,2,3,4}, {1,2,4,3}, {1,3,4,5}, {1,3,5,6}}
list-manipulation sorting
$endgroup$
3
$begingroup$
SimplySort[list], No ?
$endgroup$
– andre314
10 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to doTable[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks
$endgroup$
– nonreligious
9 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
9 hours ago
add a comment |
$begingroup$
What is the quickest way to sort a list of lists of integers, such that the first sorting criterion is the first element of the list, the next is the second element of the list and so on?
E.g. The list
list = {{1,3,4,5}, {1,2,4,3}, {1,1,2,8}, {1,3,5,6}, {1,2,3,4}}
would under these rules be sorted to
sortedlist = {{1,1,2,8}, {1,2,3,4}, {1,2,4,3}, {1,3,4,5}, {1,3,5,6}}
list-manipulation sorting
$endgroup$
What is the quickest way to sort a list of lists of integers, such that the first sorting criterion is the first element of the list, the next is the second element of the list and so on?
E.g. The list
list = {{1,3,4,5}, {1,2,4,3}, {1,1,2,8}, {1,3,5,6}, {1,2,3,4}}
would under these rules be sorted to
sortedlist = {{1,1,2,8}, {1,2,3,4}, {1,2,4,3}, {1,3,4,5}, {1,3,5,6}}
list-manipulation sorting
list-manipulation sorting
asked 10 hours ago
nonreligiousnonreligious
626 bronze badges
626 bronze badges
3
$begingroup$
SimplySort[list], No ?
$endgroup$
– andre314
10 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to doTable[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks
$endgroup$
– nonreligious
9 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
9 hours ago
add a comment |
3
$begingroup$
SimplySort[list], No ?
$endgroup$
– andre314
10 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to doTable[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks
$endgroup$
– nonreligious
9 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
9 hours ago
3
3
$begingroup$
Simply
Sort[list] , No ?$endgroup$
– andre314
10 hours ago
$begingroup$
Simply
Sort[list] , No ?$endgroup$
– andre314
10 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to do
Table[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks$endgroup$
– nonreligious
9 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to do
Table[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks$endgroup$
– nonreligious
9 hours ago
2
2
$begingroup$
@nonreligious - Rather than use
Table, map the Sort onto the list, i.e., Sort /@ list$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@nonreligious - Rather than use
Table, map the Sort onto the list, i.e., Sort /@ list$endgroup$
– Bob Hanlon
9 hours ago
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
If the sublists have equal lengths,
list[[Ordering[list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With possibly unequal lengths:
list[[Ordering[PadRight @ list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
$endgroup$
$begingroup$
I see, I had thought I would need to useSortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}]but this works.
$endgroup$
– nonreligious
9 hours ago
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in aPart::partwerror message.
$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
9 hours ago
add a comment |
$begingroup$
With equal lengths, the simplest answer, as andre314 says in the comment above, is simply Sort:
Sort[list]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With unequal lengths, kglr's Ordering + PadRight approach is probably optimal.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201171%2fsort-a-list-of-lists-by-increasing-order-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
If the sublists have equal lengths,
list[[Ordering[list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With possibly unequal lengths:
list[[Ordering[PadRight @ list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
$endgroup$
$begingroup$
I see, I had thought I would need to useSortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}]but this works.
$endgroup$
– nonreligious
9 hours ago
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in aPart::partwerror message.
$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
9 hours ago
add a comment |
$begingroup$
If the sublists have equal lengths,
list[[Ordering[list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With possibly unequal lengths:
list[[Ordering[PadRight @ list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
$endgroup$
$begingroup$
I see, I had thought I would need to useSortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}]but this works.
$endgroup$
– nonreligious
9 hours ago
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in aPart::partwerror message.
$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
9 hours ago
add a comment |
$begingroup$
If the sublists have equal lengths,
list[[Ordering[list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With possibly unequal lengths:
list[[Ordering[PadRight @ list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
$endgroup$
If the sublists have equal lengths,
list[[Ordering[list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With possibly unequal lengths:
list[[Ordering[PadRight @ list]]]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
edited 9 hours ago
answered 10 hours ago
kglrkglr
201k10 gold badges230 silver badges459 bronze badges
201k10 gold badges230 silver badges459 bronze badges
$begingroup$
I see, I had thought I would need to useSortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}]but this works.
$endgroup$
– nonreligious
9 hours ago
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in aPart::partwerror message.
$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
9 hours ago
add a comment |
$begingroup$
I see, I had thought I would need to useSortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}]but this works.
$endgroup$
– nonreligious
9 hours ago
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in aPart::partwerror message.
$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
9 hours ago
$begingroup$
I see, I had thought I would need to use
SortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}] but this works.$endgroup$
– nonreligious
9 hours ago
$begingroup$
I see, I had thought I would need to use
SortBy[list, {#[[1]] &, #[[2]] &, #[[3]] &}] but this works.$endgroup$
– nonreligious
9 hours ago
1
1
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in a
Part::partw error message.$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
If the lengths are unequal the later parts that are being explicitly referenced may not exist. This would result in a
Part::partw error message.$endgroup$
– Bob Hanlon
9 hours ago
$begingroup$
@BobHanlon, right.
Ordering with PadRight works without that issue.$endgroup$
– kglr
9 hours ago
$begingroup$
@BobHanlon, right.
Ordering with PadRight works without that issue.$endgroup$
– kglr
9 hours ago
add a comment |
$begingroup$
With equal lengths, the simplest answer, as andre314 says in the comment above, is simply Sort:
Sort[list]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With unequal lengths, kglr's Ordering + PadRight approach is probably optimal.
$endgroup$
add a comment |
$begingroup$
With equal lengths, the simplest answer, as andre314 says in the comment above, is simply Sort:
Sort[list]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With unequal lengths, kglr's Ordering + PadRight approach is probably optimal.
$endgroup$
add a comment |
$begingroup$
With equal lengths, the simplest answer, as andre314 says in the comment above, is simply Sort:
Sort[list]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With unequal lengths, kglr's Ordering + PadRight approach is probably optimal.
$endgroup$
With equal lengths, the simplest answer, as andre314 says in the comment above, is simply Sort:
Sort[list]
{{1, 1, 2, 8}, {1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 4, 5}, {1, 3, 5, 6}}
With unequal lengths, kglr's Ordering + PadRight approach is probably optimal.
answered 8 hours ago
Carl WollCarl Woll
86.2k3 gold badges110 silver badges220 bronze badges
86.2k3 gold badges110 silver badges220 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201171%2fsort-a-list-of-lists-by-increasing-order-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
Simply
Sort[list], No ?$endgroup$
– andre314
10 hours ago
$begingroup$
Yes, you're right - I was trying to do something more complicated than this simple example which was a list of lists of lists, but I could use this to do
Table[Sort[list[[i]] , {i, 1, Length[list]}]. Thanks$endgroup$
– nonreligious
9 hours ago
2
$begingroup$
@nonreligious - Rather than use
Table, map theSortonto thelist, i.e.,Sort /@ list$endgroup$
– Bob Hanlon
9 hours ago