Mapping string into integersDistinguishing slots in a function mapping Position across a listMapping over an association producing an unexpected resultConverting a list of associations into a single associationReplace single element of a nested list with multiple elementsFlattening a list desiring a specific formatString Join but not fullyManipulation of two lists of strings and integersDeleting unwanted elements in lists of wordsCoverting list of string into integers and reshaping the original list

Find number 8 with the least number of tries

Meaning of 'pound' in "felt a fury that was not his own pound through his body"

A man condemned to serve his sentence in other times

Does immunity to fear prevent a mummy's Dreadful Glare from paralyzing a character?

how to say 'nerd' or 'geek' in french?

If I did not sign promotion bonus document, my career would be over. Is this duress?

Why does Principal Vagina say, "no relation" after introducing himself?

In the twin paradox does the returning twin also come back permanently length contracted flatter than the twin on earth?

Easy way of generating a 50-150W load @12V

Usefulness of Nash embedding theorem

How do I get my boyfriend to remove pictures of his ex girlfriend hanging in his apartment?

Is there a historical explanation as to why the USA people are so litigious compared to France?

Does a restocking fee still qualify as a business expense?

Did Terry Pratchett ever explain the inspiration behind Luggage?

How do I copy an installed steam game on my PC to an external hard drive?

Remove last letter 4 times, get a real word each time, starting word is a car model

How to snip same part of screen as last time?

Do businesses save their customers' credit card information until the payment is finalized?

Does my protagonist need to be the most important character?

Charges from Dollar General have never shown up on my debit card - how to resolve?

This is a Noteworthy Riddle

When to use the gestalt principle of common region?

What could possibly power an Alcubierre drive?

What does the British parliament hope to achieve by requesting a third Brexit extension?



Mapping string into integers


Distinguishing slots in a function mapping Position across a listMapping over an association producing an unexpected resultConverting a list of associations into a single associationReplace single element of a nested list with multiple elementsFlattening a list desiring a specific formatString Join but not fullyManipulation of two lists of strings and integersDeleting unwanted elements in lists of wordsCoverting list of string into integers and reshaping the original list






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;

.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;








4














$begingroup$


Suppose I have the following list,



l = "b", "c", "d", "e", "b", "a", "b", "d", "e"


and further suppose I have the following association,



l1=<|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>


I wonder how can I replace the keys into my list such that I get,



2, 3, 4, 5, 2, 1, 2, 4, 5









share|improve this question











$endgroup$






















    4














    $begingroup$


    Suppose I have the following list,



    l = "b", "c", "d", "e", "b", "a", "b", "d", "e"


    and further suppose I have the following association,



    l1=<|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>


    I wonder how can I replace the keys into my list such that I get,



    2, 3, 4, 5, 2, 1, 2, 4, 5









    share|improve this question











    $endgroup$


















      4












      4








      4





      $begingroup$


      Suppose I have the following list,



      l = "b", "c", "d", "e", "b", "a", "b", "d", "e"


      and further suppose I have the following association,



      l1=<|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>


      I wonder how can I replace the keys into my list such that I get,



      2, 3, 4, 5, 2, 1, 2, 4, 5









      share|improve this question











      $endgroup$




      Suppose I have the following list,



      l = "b", "c", "d", "e", "b", "a", "b", "d", "e"


      and further suppose I have the following association,



      l1=<|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>


      I wonder how can I replace the keys into my list such that I get,



      2, 3, 4, 5, 2, 1, 2, 4, 5






      list-manipulation map






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question



      share|improve this question








      edited 6 hours ago









      Henrik Schumacher

      69.1k5 gold badges101 silver badges193 bronze badges




      69.1k5 gold badges101 silver badges193 bronze badges










      asked 8 hours ago









      WilliamWilliam

      1,1736 silver badges9 bronze badges




      1,1736 silver badges9 bronze badges























          4 Answers
          4






          active

          oldest

          votes


















          5
















          $begingroup$

          The following gives you a "reversed" version of your association, with keys and values flipped:



          l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;

          lookup = First /@ PositionIndex@l1
          (* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)


          You can then use ReplaceAll (/.) to do the replacement:



          l = "b", "c", "d", "e", "b", "a", "b", "d", "e";

          l /. lookup
          (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


          Alternatives



          Other possible solutions for creating lookup:



          lookup = <|Reverse /@ Normal@l1|>
          lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)





          share|improve this answer












          $endgroup$






















            5
















            $begingroup$

            For the specific numbering in OP, you can also use LetterNumber:



            LetterNumber[l]



            2, 3, 4, 5, 2, 1, 2, 4, 5







            share|improve this answer












            $endgroup$






















              4
















              $begingroup$

              l /. Reverse /@ Normal[l1]

              (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


              or



              l /. AssociationMap[Reverse, l1]

              (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)





              share|improve this answer












              $endgroup$






















                1
















                $begingroup$

                For this particular mapping, you could also use ToCharacterCode:



                ToCharacterCode[StringJoin /@ l] - First@ToCharacterCode@"a" + 1



                2, 3, 4, 5, 2, 1, 2, 4, 5







                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/4.0/"u003ecc by-sa 4.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%2f207515%2fmapping-string-into-integers%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown


























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  5
















                  $begingroup$

                  The following gives you a "reversed" version of your association, with keys and values flipped:



                  l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;

                  lookup = First /@ PositionIndex@l1
                  (* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)


                  You can then use ReplaceAll (/.) to do the replacement:



                  l = "b", "c", "d", "e", "b", "a", "b", "d", "e";

                  l /. lookup
                  (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                  Alternatives



                  Other possible solutions for creating lookup:



                  lookup = <|Reverse /@ Normal@l1|>
                  lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)





                  share|improve this answer












                  $endgroup$



















                    5
















                    $begingroup$

                    The following gives you a "reversed" version of your association, with keys and values flipped:



                    l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;

                    lookup = First /@ PositionIndex@l1
                    (* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)


                    You can then use ReplaceAll (/.) to do the replacement:



                    l = "b", "c", "d", "e", "b", "a", "b", "d", "e";

                    l /. lookup
                    (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                    Alternatives



                    Other possible solutions for creating lookup:



                    lookup = <|Reverse /@ Normal@l1|>
                    lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)





                    share|improve this answer












                    $endgroup$

















                      5














                      5










                      5







                      $begingroup$

                      The following gives you a "reversed" version of your association, with keys and values flipped:



                      l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;

                      lookup = First /@ PositionIndex@l1
                      (* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)


                      You can then use ReplaceAll (/.) to do the replacement:



                      l = "b", "c", "d", "e", "b", "a", "b", "d", "e";

                      l /. lookup
                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                      Alternatives



                      Other possible solutions for creating lookup:



                      lookup = <|Reverse /@ Normal@l1|>
                      lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)





                      share|improve this answer












                      $endgroup$



                      The following gives you a "reversed" version of your association, with keys and values flipped:



                      l1 = <|1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e"|>;

                      lookup = First /@ PositionIndex@l1
                      (* <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|> *)


                      You can then use ReplaceAll (/.) to do the replacement:



                      l = "b", "c", "d", "e", "b", "a", "b", "d", "e";

                      l /. lookup
                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                      Alternatives



                      Other possible solutions for creating lookup:



                      lookup = <|Reverse /@ Normal@l1|>
                      lookup = Reverse /@ Normal@l1 (* doesn't need to be an association *)






                      share|improve this answer















                      share|improve this answer




                      share|improve this answer



                      share|improve this answer








                      edited 8 hours ago

























                      answered 8 hours ago









                      Lukas LangLukas Lang

                      10.6k1 gold badge14 silver badges41 bronze badges




                      10.6k1 gold badge14 silver badges41 bronze badges


























                          5
















                          $begingroup$

                          For the specific numbering in OP, you can also use LetterNumber:



                          LetterNumber[l]



                          2, 3, 4, 5, 2, 1, 2, 4, 5







                          share|improve this answer












                          $endgroup$



















                            5
















                            $begingroup$

                            For the specific numbering in OP, you can also use LetterNumber:



                            LetterNumber[l]



                            2, 3, 4, 5, 2, 1, 2, 4, 5







                            share|improve this answer












                            $endgroup$

















                              5














                              5










                              5







                              $begingroup$

                              For the specific numbering in OP, you can also use LetterNumber:



                              LetterNumber[l]



                              2, 3, 4, 5, 2, 1, 2, 4, 5







                              share|improve this answer












                              $endgroup$



                              For the specific numbering in OP, you can also use LetterNumber:



                              LetterNumber[l]



                              2, 3, 4, 5, 2, 1, 2, 4, 5








                              share|improve this answer















                              share|improve this answer




                              share|improve this answer



                              share|improve this answer








                              edited 4 hours ago

























                              answered 6 hours ago









                              kglrkglr

                              220k10 gold badges250 silver badges506 bronze badges




                              220k10 gold badges250 silver badges506 bronze badges
























                                  4
















                                  $begingroup$

                                  l /. Reverse /@ Normal[l1]

                                  (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                                  or



                                  l /. AssociationMap[Reverse, l1]

                                  (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)





                                  share|improve this answer












                                  $endgroup$



















                                    4
















                                    $begingroup$

                                    l /. Reverse /@ Normal[l1]

                                    (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                                    or



                                    l /. AssociationMap[Reverse, l1]

                                    (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)





                                    share|improve this answer












                                    $endgroup$

















                                      4














                                      4










                                      4







                                      $begingroup$

                                      l /. Reverse /@ Normal[l1]

                                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                                      or



                                      l /. AssociationMap[Reverse, l1]

                                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)





                                      share|improve this answer












                                      $endgroup$



                                      l /. Reverse /@ Normal[l1]

                                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)


                                      or



                                      l /. AssociationMap[Reverse, l1]

                                      (* 2, 3, 4, 5, 2, 1, 2, 4, 5 *)






                                      share|improve this answer















                                      share|improve this answer




                                      share|improve this answer



                                      share|improve this answer








                                      edited 8 hours ago

























                                      answered 8 hours ago









                                      Suba ThomasSuba Thomas

                                      4,26411 silver badges20 bronze badges




                                      4,26411 silver badges20 bronze badges
























                                          1
















                                          $begingroup$

                                          For this particular mapping, you could also use ToCharacterCode:



                                          ToCharacterCode[StringJoin /@ l] - First@ToCharacterCode@"a" + 1



                                          2, 3, 4, 5, 2, 1, 2, 4, 5







                                          share|improve this answer










                                          $endgroup$



















                                            1
















                                            $begingroup$

                                            For this particular mapping, you could also use ToCharacterCode:



                                            ToCharacterCode[StringJoin /@ l] - First@ToCharacterCode@"a" + 1



                                            2, 3, 4, 5, 2, 1, 2, 4, 5







                                            share|improve this answer










                                            $endgroup$

















                                              1














                                              1










                                              1







                                              $begingroup$

                                              For this particular mapping, you could also use ToCharacterCode:



                                              ToCharacterCode[StringJoin /@ l] - First@ToCharacterCode@"a" + 1



                                              2, 3, 4, 5, 2, 1, 2, 4, 5







                                              share|improve this answer










                                              $endgroup$



                                              For this particular mapping, you could also use ToCharacterCode:



                                              ToCharacterCode[StringJoin /@ l] - First@ToCharacterCode@"a" + 1



                                              2, 3, 4, 5, 2, 1, 2, 4, 5








                                              share|improve this answer













                                              share|improve this answer




                                              share|improve this answer



                                              share|improve this answer










                                              answered 6 hours ago









                                              Carl WollCarl Woll

                                              92k3 gold badges121 silver badges233 bronze badges




                                              92k3 gold badges121 silver badges233 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%2f207515%2fmapping-string-into-integers%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