Sort a list of lists by increasing order of elementsImplementing 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
Hard for me to understand one tip written in "The as-if rule" of cppreference
Rear derailleur got caught in the spokes, what could be a root cause
Installed software from source, how to say yum not to install it from package?
A quine of sorts
What are the children of two Muggle-borns called?
Example of query execution plan where the cardinality estimation makes a difference
Why did the Apple //e make a hideous noise if you inserted the disk upside down?
Single method for different parameterized mysql command
Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?
Delete all files from a folder using a bat that match a certain pattern in Windows 10
What does 5d4 x 10 gp mean?
Partitioning weighted elements with a restriction on total partition weight
Should Catholics in a state of grace call themselves sinners?
Why were the first airplanes "backwards"?
How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?
Fully submerged water bath for stove top baking?
How do banks maintain reserves?
The alcoholic village festival
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Why wasn't ASCII designed with a contiguous alphanumeric character order?
Correct use of the the idiom 'Гнать/Катить бочку'
Is it theoretically possible to hack printer using scanner tray?
Avoiding repetition when using the "snprintf idiom" to write text
What prevents a US state from colonizing a smaller state?
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
8 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
8 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
8 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 9 hours ago
nonreligiousnonreligious
626 bronze badges
626 bronze badges
3
$begingroup$
SimplySort[list], No ?
$endgroup$
– andre314
8 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
8 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
8 hours ago
add a comment |
3
$begingroup$
SimplySort[list], No ?
$endgroup$
– andre314
8 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
8 hours ago
2
$begingroup$
@nonreligious - Rather than useTable, map theSortonto thelist, i.e.,Sort /@ list
$endgroup$
– Bob Hanlon
8 hours ago
3
3
$begingroup$
Simply
Sort[list] , No ?$endgroup$
– andre314
8 hours ago
$begingroup$
Simply
Sort[list] , No ?$endgroup$
– andre314
8 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
8 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
8 hours ago
2
2
$begingroup$
@nonreligious - Rather than use
Table, map the Sort onto the list, i.e., Sort /@ list$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@nonreligious - Rather than use
Table, map the Sort onto the list, i.e., Sort /@ list$endgroup$
– Bob Hanlon
8 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
8 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
8 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
8 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 8 hours ago
answered 9 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
8 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.OrderingwithPadRightworks without that issue.
$endgroup$
– kglr
8 hours ago
$begingroup$
I see, I had thought I would need to use
SortBy[list, #[[1]] &, #[[2]] &, #[[3]] &] but this works.$endgroup$
– nonreligious
8 hours ago
$begingroup$
I see, I had thought I would need to use
SortBy[list, #[[1]] &, #[[2]] &, #[[3]] &] but this works.$endgroup$
– nonreligious
8 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
8 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
8 hours ago
$begingroup$
@BobHanlon, right.
Ordering with PadRight works without that issue.$endgroup$
– kglr
8 hours ago
$begingroup$
@BobHanlon, right.
Ordering with PadRight works without that issue.$endgroup$
– kglr
8 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 7 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
8 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
8 hours ago
2
$begingroup$
@nonreligious - Rather than use
Table, map theSortonto thelist, i.e.,Sort /@ list$endgroup$
– Bob Hanlon
8 hours ago