Sort a list by elements of another listOrdered indices of a multiple product or sumThe efficiency compare between Flatten[#, 1] & and Join @@ # &Lexicographic ordering of lists-of-lists?How-to select an entry from a list of pairs that meets a condition depending the 2nd element of each pairList of (sub-)lists - query sub-lists by names?Can we intelligently control evaluation in Thread?Sort list but keeping the number of swaps requiredFind positions in which list elements are equalHow can I check if elements between lists are equal?comparing lists of strings

Does "every" first-order theory have a finitely axiomatizable conservative extension?

Type int? vs type int

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

What to do with wrong results in talks?

Was Spock the First Vulcan in Starfleet?

Term for the "extreme-extension" version of a straw man fallacy?

Why not increase contact surface when reentering the atmosphere?

Is there a problem with hiding "forgot password" until it's needed?

How many times can American Tourist re-enter UK in same 6 month period?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Why Were Madagascar and New Zealand Discovered So Late?

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?

Can I boil off chlorine? Does it evaporate quickly at high temperatures?

Are student evaluations of teaching assistants read by others in the faculty?

What is the difference between "behavior" and "behaviour"?

How do I go from 300 unfinished/half written blog posts, to published posts?

Is this version of a gravity generator feasible?

What is the best translation for "slot" in the context of multiplayer video games?

Is it okay for two “sein” to be next to each other?

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

Is HostGator storing my password in plaintext?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

What's this thing which looks like a water sensor inside a PC mouse?



Sort a list by elements of another list


Ordered indices of a multiple product or sumThe efficiency compare between Flatten[#, 1] & and Join @@ # &Lexicographic ordering of lists-of-lists?How-to select an entry from a list of pairs that meets a condition depending the 2nd element of each pairList of (sub-)lists - query sub-lists by names?Can we intelligently control evaluation in Thread?Sort list but keeping the number of swaps requiredFind positions in which list elements are equalHow can I check if elements between lists are equal?comparing lists of strings













3












$begingroup$


I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.



I have to lists



list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)


Now I want to sort list2according to the list1-order so the output should be:



(*A,4,B,5,C,1*)









share|improve this question









$endgroup$











  • $begingroup$
    to be more specific list2should be sorted according to the first column of list1
    $endgroup$
    – M.A.
    1 hour ago















3












$begingroup$


I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.



I have to lists



list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)


Now I want to sort list2according to the list1-order so the output should be:



(*A,4,B,5,C,1*)









share|improve this question









$endgroup$











  • $begingroup$
    to be more specific list2should be sorted according to the first column of list1
    $endgroup$
    – M.A.
    1 hour ago













3












3








3





$begingroup$


I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.



I have to lists



list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)


Now I want to sort list2according to the list1-order so the output should be:



(*A,4,B,5,C,1*)









share|improve this question









$endgroup$




I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.



I have to lists



list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)


Now I want to sort list2according to the list1-order so the output should be:



(*A,4,B,5,C,1*)






list-manipulation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









M.A.M.A.

545




545











  • $begingroup$
    to be more specific list2should be sorted according to the first column of list1
    $endgroup$
    – M.A.
    1 hour ago
















  • $begingroup$
    to be more specific list2should be sorted according to the first column of list1
    $endgroup$
    – M.A.
    1 hour ago















$begingroup$
to be more specific list2should be sorted according to the first column of list1
$endgroup$
– M.A.
1 hour ago




$begingroup$
to be more specific list2should be sorted according to the first column of list1
$endgroup$
– M.A.
1 hour ago










2 Answers
2






active

oldest

votes


















3












$begingroup$

idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]



A, 4, B, 5, C, 1







share|improve this answer











$endgroup$




















    1












    $begingroup$

    Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]



    A, 4, B, 5, C, 1







    share|improve this answer









    $endgroup$












      Your Answer





      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      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%2f194061%2fsort-a-list-by-elements-of-another-list%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









      3












      $begingroup$

      idx = Lookup[
      AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
      list2[[All, 1]]
      ];
      list2[[idx]]



      A, 4, B, 5, C, 1







      share|improve this answer











      $endgroup$

















        3












        $begingroup$

        idx = Lookup[
        AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
        list2[[All, 1]]
        ];
        list2[[idx]]



        A, 4, B, 5, C, 1







        share|improve this answer











        $endgroup$















          3












          3








          3





          $begingroup$

          idx = Lookup[
          AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
          list2[[All, 1]]
          ];
          list2[[idx]]



          A, 4, B, 5, C, 1







          share|improve this answer











          $endgroup$



          idx = Lookup[
          AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
          list2[[All, 1]]
          ];
          list2[[idx]]



          A, 4, B, 5, C, 1








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 1 hour ago









          Henrik SchumacherHenrik Schumacher

          58.1k580160




          58.1k580160





















              1












              $begingroup$

              Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]



              A, 4, B, 5, C, 1







              share|improve this answer









              $endgroup$

















                1












                $begingroup$

                Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]



                A, 4, B, 5, C, 1







                share|improve this answer









                $endgroup$















                  1












                  1








                  1





                  $begingroup$

                  Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]



                  A, 4, B, 5, C, 1







                  share|improve this answer









                  $endgroup$



                  Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]



                  A, 4, B, 5, C, 1








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 11 mins ago









                  MikeYMikeY

                  3,473714




                  3,473714



























                      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%2f194061%2fsort-a-list-by-elements-of-another-list%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

                      名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

                      格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订