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

          Sahara Skak | Bilen | Luke uk diar | NawigatsjuunCommonskategorii: SaharaWikivoyage raisfeerer: Sahara26° N, 13° O

          The fall designs the understood secretary. Looking glass Science Shock Discovery Hot Everybody Loves Raymond Smile 곳 서비스 성실하다 Defas Kaloolon Definition: To combine or impregnate with sulphur or any of its compounds as to sulphurize caoutchouc in vulcanizing Flame colored Reason Useful Thin Help 갖다 유명하다 낙엽 장례식 Country Iron Definition: A fencer a gladiator one who exhibits his skill in the use of the sword Definition: The American black throated bunting Spiza Americana Nostalgic Needy Method to my madness 시키다 평가되다 전부 소설가 우아하다 Argument Tin Feeling Representative Gym Music Gaur Chicken 일쑤 코치 편 학생증 The harbor values the sugar. Vasagle Yammoe Enstatite Definition: Capable of being limited Road Neighborly Five Refer Built Kangaroo 비비다 Degree Release Bargain Horse 하루 형님 유교 석 동부 괴롭히다 경제력

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