Selecting elements from a list where the order is set by another listHow to order a list to match the order of another list?Creating sums of elements from a listGenerating an ordered list of pairs of elements from ordered listsGenerating a random sample of elements from a list that includes a subset of the listDeleteDuplicates Delete elements of a listMatching the order of a master list of lists from a random list of listshow to apply Alternatives command to delete cases from a list?Adding multiplied corresponding elements from two different listsDelete elements of a list that appear in another listRemoving zeros from a list of equationsSelecting elements satisfying a condition

Is “snitty” a popular American English term? What is its origin?

Hostile Divisor Numbers

Adding command shortcuts to /bin

History of the kernel of a homomorphism?

What do I do if my advisor made a mistake?

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

A factorization game

Is Benjen dead?

How can Internet speed be 10 times slower without a router than when using the same connection with a router?

Why is "breaking the mould" positively connoted?

Are there terms in German for different skull shapes?

How can I get people to remember my character's gender?

As a GM, is it bad form to ask for a moment to think when improvising?

Dangerous workplace travelling

GitLab account hacked and repo wiped

SOQL query WHERE filter by specific months

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?

Has the United States ever had a non-Christian President?

Side effects of Initiation by a Guru?

How do I allocate more memory to an app on Sheepshaver running Mac OS 9?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

Why aren't nationalizations in Russia described as socialist?

Kanji etymology of 毎?



Selecting elements from a list where the order is set by another list


How to order a list to match the order of another list?Creating sums of elements from a listGenerating an ordered list of pairs of elements from ordered listsGenerating a random sample of elements from a list that includes a subset of the listDeleteDuplicates Delete elements of a listMatching the order of a master list of lists from a random list of listshow to apply Alternatives command to delete cases from a list?Adding multiplied corresponding elements from two different listsDelete elements of a list that appear in another listRemoving zeros from a list of equationsSelecting elements satisfying a condition













3












$begingroup$


I have two lists, list A and list B. All of the elements of A are members of B. The order of B is fixed but the order of A is random. I need to arrange the elements in A as given in B.



Example let A



A=5,2,8


and B is



B=9,2,6,8,5,1


I need to reorder A to be:



A=2,8,5


I'm looking for a clever one-liner. This is similar to How to order a list to match the order of another list? but there the two lists have the same length. I tried some variations on adding some padding.










share|improve this question









$endgroup$
















    3












    $begingroup$


    I have two lists, list A and list B. All of the elements of A are members of B. The order of B is fixed but the order of A is random. I need to arrange the elements in A as given in B.



    Example let A



    A=5,2,8


    and B is



    B=9,2,6,8,5,1


    I need to reorder A to be:



    A=2,8,5


    I'm looking for a clever one-liner. This is similar to How to order a list to match the order of another list? but there the two lists have the same length. I tried some variations on adding some padding.










    share|improve this question









    $endgroup$














      3












      3








      3





      $begingroup$


      I have two lists, list A and list B. All of the elements of A are members of B. The order of B is fixed but the order of A is random. I need to arrange the elements in A as given in B.



      Example let A



      A=5,2,8


      and B is



      B=9,2,6,8,5,1


      I need to reorder A to be:



      A=2,8,5


      I'm looking for a clever one-liner. This is similar to How to order a list to match the order of another list? but there the two lists have the same length. I tried some variations on adding some padding.










      share|improve this question









      $endgroup$




      I have two lists, list A and list B. All of the elements of A are members of B. The order of B is fixed but the order of A is random. I need to arrange the elements in A as given in B.



      Example let A



      A=5,2,8


      and B is



      B=9,2,6,8,5,1


      I need to reorder A to be:



      A=2,8,5


      I'm looking for a clever one-liner. This is similar to How to order a list to match the order of another list? but there the two lists have the same length. I tried some variations on adding some padding.







      list-manipulation core-language






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      c186282c186282

      828612




      828612




















          1 Answer
          1






          active

          oldest

          votes


















          4












          $begingroup$

          SortBy[FirstPosition[#] @B&]@A



          2, 8, 5




          Also,



          Cases[Alternatives @@ A] @ B



          2, 8, 5




          DeleteCases[Except[Alternatives @@ A]] @ B



          2, 8, 5







          share|improve this answer











          $endgroup$








          • 2




            $begingroup$
            Cases[B, Alternatives@@A] is real-world poetry.
            $endgroup$
            – Roman
            23 mins ago











          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%2f197648%2fselecting-elements-from-a-list-where-the-order-is-set-by-another-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4












          $begingroup$

          SortBy[FirstPosition[#] @B&]@A



          2, 8, 5




          Also,



          Cases[Alternatives @@ A] @ B



          2, 8, 5




          DeleteCases[Except[Alternatives @@ A]] @ B



          2, 8, 5







          share|improve this answer











          $endgroup$








          • 2




            $begingroup$
            Cases[B, Alternatives@@A] is real-world poetry.
            $endgroup$
            – Roman
            23 mins ago















          4












          $begingroup$

          SortBy[FirstPosition[#] @B&]@A



          2, 8, 5




          Also,



          Cases[Alternatives @@ A] @ B



          2, 8, 5




          DeleteCases[Except[Alternatives @@ A]] @ B



          2, 8, 5







          share|improve this answer











          $endgroup$








          • 2




            $begingroup$
            Cases[B, Alternatives@@A] is real-world poetry.
            $endgroup$
            – Roman
            23 mins ago













          4












          4








          4





          $begingroup$

          SortBy[FirstPosition[#] @B&]@A



          2, 8, 5




          Also,



          Cases[Alternatives @@ A] @ B



          2, 8, 5




          DeleteCases[Except[Alternatives @@ A]] @ B



          2, 8, 5







          share|improve this answer











          $endgroup$



          SortBy[FirstPosition[#] @B&]@A



          2, 8, 5




          Also,



          Cases[Alternatives @@ A] @ B



          2, 8, 5




          DeleteCases[Except[Alternatives @@ A]] @ B



          2, 8, 5








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 19 mins ago

























          answered 4 hours ago









          kglrkglr

          191k10210430




          191k10210430







          • 2




            $begingroup$
            Cases[B, Alternatives@@A] is real-world poetry.
            $endgroup$
            – Roman
            23 mins ago












          • 2




            $begingroup$
            Cases[B, Alternatives@@A] is real-world poetry.
            $endgroup$
            – Roman
            23 mins ago







          2




          2




          $begingroup$
          Cases[B, Alternatives@@A] is real-world poetry.
          $endgroup$
          – Roman
          23 mins ago




          $begingroup$
          Cases[B, Alternatives@@A] is real-world poetry.
          $endgroup$
          – Roman
          23 mins ago

















          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%2f197648%2fselecting-elements-from-a-list-where-the-order-is-set-by-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

          ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

          Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

          19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу