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

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

Correct way of drawing empty, half-filled and fully filled circles?

Is an HNN extension of a virtually torsion-free group virtually torsion-free?

Is the book wrong about the Nyquist Sampling Criterion?

My first C++ game (snake console game)

Why do these characters still seem to be the same age after the events of Endgame?

How long would it take for people to notice a mass disappearance?

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

Are pressure-treated posts that have been submerged for a few days ruined?

What do I do if my advisor made a mistake?

How do I calculate how many of an item I'll have in this inventory system?

What to use instead of cling film to wrap pastry

Does XQuartz work on macOS Mojave?

Are the Night's Watch still required?

Side effects of Initiation by a Guru?

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

Would a small hole in a Faraday cage drastically reduce its effectiveness at blocking interference?

How to deal with employer who keeps me at work after working hours

Adding command shortcuts to /bin

What do "Sech" and "Vich" mean in this sentence?

Why do people keep telling me that I am a bad photographer?

Has the Hulk always been able to talk?

If all diagonals are drawn in a regular polygon from a vertex, the angles formed in that vertex are equal

Install LibreOffice-Writer Only not LibreOffice whole package



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













4












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
















    4












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














      4












      4








      4





      $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

      833612




      833612




















          1 Answer
          1






          active

          oldest

          votes


















          5












          $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
            29 mins ago










          • $begingroup$
            +1. Also: SortBy[A, PositionIndex[B]]
            $endgroup$
            – WReach
            2 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









          5












          $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
            29 mins ago










          • $begingroup$
            +1. Also: SortBy[A, PositionIndex[B]]
            $endgroup$
            – WReach
            2 mins ago















          5












          $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
            29 mins ago










          • $begingroup$
            +1. Also: SortBy[A, PositionIndex[B]]
            $endgroup$
            – WReach
            2 mins ago













          5












          5








          5





          $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 25 mins ago

























          answered 4 hours ago









          kglrkglr

          191k10210430




          191k10210430







          • 2




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










          • $begingroup$
            +1. Also: SortBy[A, PositionIndex[B]]
            $endgroup$
            – WReach
            2 mins ago












          • 2




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










          • $begingroup$
            +1. Also: SortBy[A, PositionIndex[B]]
            $endgroup$
            – WReach
            2 mins ago







          2




          2




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




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












          $begingroup$
          +1. Also: SortBy[A, PositionIndex[B]]
          $endgroup$
          – WReach
          2 mins ago




          $begingroup$
          +1. Also: SortBy[A, PositionIndex[B]]
          $endgroup$
          – WReach
          2 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

          Log på Navigationsmenu

          Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

          Nuuk Indholdsfortegnelse Etyomologi | Historie | Geografi | Transport og infrastruktur | Politik og administration | Uddannelsesinstitutioner | Kultur | Venskabsbyer | Noter | Eksterne henvisninger | Se også | Navigationsmenuwww.sermersooq.gl64°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.75064°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.750DMI - KlimanormalerSalmonsen, s. 850Grønlands Naturinstitut undersøger rensdyr i Akia og Maniitsoq foråret 2008Grønlands NaturinstitutNy vej til Qinngorput indviet i dagAntallet af biler i Nuuk må begrænsesNy taxacentral mødt med demonstrationKøreplan. Rute 1, 2 og 3SnescootersporNuukNord er for storSkoler i Kommuneqarfik SermersooqAtuarfik Samuel KleinschmidtKangillinguit AtuarfiatNuussuup AtuarfiaNuuk Internationale FriskoleIlinniarfissuaq, Grønlands SeminariumLedelseÅrsberetning for 2008Kunst og arkitekturÅrsberetning for 2008Julie om naturenNuuk KunstmuseumSilamiutGrønlands Nationalmuseum og ArkivStatistisk ÅrbogGrønlands LandsbibliotekStore koncerter på stribeVandhund nummer 1.000.000Kommuneqarfik Sermersooq – MalikForsidenVenskabsbyerLyngby-Taarbæk i GrønlandArctic Business NetworkWinter Cities 2008 i NuukDagligt opdaterede satellitbilleder fra NuukområdetKommuneqarfik Sermersooqs hjemmesideTurist i NuukGrønlands Statistiks databankGrønlands Hjemmestyres valgresultaterrrWorldCat124325457671310-5