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













3












$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










share|improve this question









$endgroup$







  • 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 the Sort onto the list, i.e., Sort /@ list
    $endgroup$
    – Bob Hanlon
    8 hours ago















3












$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










share|improve this question









$endgroup$







  • 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 the Sort onto the list, i.e., Sort /@ list
    $endgroup$
    – Bob Hanlon
    8 hours ago













3












3








3





$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










share|improve this question









$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 9 hours ago









nonreligiousnonreligious

626 bronze badges




626 bronze badges







  • 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 the Sort onto the list, i.e., Sort /@ list
    $endgroup$
    – Bob Hanlon
    8 hours ago












  • 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 the Sort onto the list, 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










2 Answers
2






active

oldest

votes


















5












$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







share|improve this answer











$endgroup$












  • $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




    $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


















1












$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.






share|improve this answer









$endgroup$















    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
    );



    );













    draft saved

    draft discarded


















    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









    5












    $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







    share|improve this answer











    $endgroup$












    • $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




      $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















    5












    $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







    share|improve this answer











    $endgroup$












    • $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




      $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













    5












    5








    5





    $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







    share|improve this answer











    $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








    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 use SortBy[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 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$
      I see, I had thought I would need to use SortBy[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 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$
    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











    1












    $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.






    share|improve this answer









    $endgroup$

















      1












      $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.






      share|improve this answer









      $endgroup$















        1












        1








        1





        $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.






        share|improve this answer









        $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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 7 hours ago









        Carl WollCarl Woll

        86.2k3 gold badges110 silver badges220 bronze badges




        86.2k3 gold badges110 silver badges220 bronze badges



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480