Pythonic code to convert 3 digit number into all possible letter combinationsSplitting an array of numbers...

How can bays and straits be determined in a procedurally generated map?

What does "enim et" mean?

What do you call a Matrix-like slowdown and camera movement effect?

Is there a familial term for apples and pears?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Is Social Media Science Fiction?

The magic money tree problem

Why is "Reports" in sentence down without "The"

XeLaTeX and pdfLaTeX ignore hyphenation

Email Account under attack (really) - anything I can do?

How to make payment on the internet without leaving a money trail?

What are these boxed doors outside store fronts in New York?

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

Concept of linear mappings are confusing me

Chess with symmetric move-square

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

least quadratic residue under GRH: an EXPLICIT bound

How do you conduct xenoanthropology after first contact?

Can you lasso down a wizard who is using the Levitate spell?

What is the meaning of "of trouble" in the following sentence?

A function which translates a sentence to title-case

What would happen to a modern skyscraper if it rains micro blackholes?



Pythonic code to convert 3 digit number into all possible letter combinations


Splitting an array of numbers into all possible combinationsDynamic Programming for printing additive numbers up to digits nProject Euler 62: cubic permutations, logicPython IBAN validationLast five non-zero digits of a factorial in base bHackerrank Gemstones SolutionRepeatedly multiplying digits until a single digit is obtainedSolution to Google Code Jam 2008 round 1C problem BLeetcode number of atoms solution using stackGenerating all permutations of 1 digit, 2 equal letters and 2 different letters efficiently






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







2












$begingroup$


Given a dictionary where 1:a , 2:b ... 26:z. I need to find all the possible letter combinations that can be formed from the three digits.



Either each digit should translate to a letter individually or you can combine adjacent digits to check for a letter. You can't change the order of the digits. For example -



121 translates to aba, au, la;



151 translates to aea, oa;



101 translates to ja;



I was able to get this working but I feel my code is not very "pythonic". I am trying to figure out a more efficient & python-like solution for this problem.



# creating the dict that has keys as digits and values as letters
root_dict = {}
for num in range(0,26):
root_dict[str(num+1)] = string.ascii_lowercase[num]

# asking user for a three digit number
sequence_to_convert = raw_input('Enter three digit number n')

# storing all possible permutations from the three digit number
first_permutation = sequence_to_convert[0]
second_permutation = sequence_to_convert[1]
third_permutation = sequence_to_convert[2]
fourth_permutation = sequence_to_convert[0]+sequence_to_convert[1]
fifth_permutation = sequence_to_convert[1]+sequence_to_convert[2]

# checking if the permutations exist in the dict, if so print corresponding letters
if first_permutation in root_dict and second_permutation in root_dict and third_permutation in root_dict:
print root_dict[first_permutation]+root_dict[second_permutation]+root_dict[third_permutation]
if first_permutation in root_dict and fifth_permutation in root_dict:
print root_dict[first_permutation]+root_dict[fifth_permutation]
if fourth_permutation in root_dict and third_permutation in root_dict:
print root_dict[fourth_permutation]+root_dict[third_permutation]









share|improve this question







New contributor




user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



















    2












    $begingroup$


    Given a dictionary where 1:a , 2:b ... 26:z. I need to find all the possible letter combinations that can be formed from the three digits.



    Either each digit should translate to a letter individually or you can combine adjacent digits to check for a letter. You can't change the order of the digits. For example -



    121 translates to aba, au, la;



    151 translates to aea, oa;



    101 translates to ja;



    I was able to get this working but I feel my code is not very "pythonic". I am trying to figure out a more efficient & python-like solution for this problem.



    # creating the dict that has keys as digits and values as letters
    root_dict = {}
    for num in range(0,26):
    root_dict[str(num+1)] = string.ascii_lowercase[num]

    # asking user for a three digit number
    sequence_to_convert = raw_input('Enter three digit number n')

    # storing all possible permutations from the three digit number
    first_permutation = sequence_to_convert[0]
    second_permutation = sequence_to_convert[1]
    third_permutation = sequence_to_convert[2]
    fourth_permutation = sequence_to_convert[0]+sequence_to_convert[1]
    fifth_permutation = sequence_to_convert[1]+sequence_to_convert[2]

    # checking if the permutations exist in the dict, if so print corresponding letters
    if first_permutation in root_dict and second_permutation in root_dict and third_permutation in root_dict:
    print root_dict[first_permutation]+root_dict[second_permutation]+root_dict[third_permutation]
    if first_permutation in root_dict and fifth_permutation in root_dict:
    print root_dict[first_permutation]+root_dict[fifth_permutation]
    if fourth_permutation in root_dict and third_permutation in root_dict:
    print root_dict[fourth_permutation]+root_dict[third_permutation]









    share|improve this question







    New contributor




    user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      2












      2








      2





      $begingroup$


      Given a dictionary where 1:a , 2:b ... 26:z. I need to find all the possible letter combinations that can be formed from the three digits.



      Either each digit should translate to a letter individually or you can combine adjacent digits to check for a letter. You can't change the order of the digits. For example -



      121 translates to aba, au, la;



      151 translates to aea, oa;



      101 translates to ja;



      I was able to get this working but I feel my code is not very "pythonic". I am trying to figure out a more efficient & python-like solution for this problem.



      # creating the dict that has keys as digits and values as letters
      root_dict = {}
      for num in range(0,26):
      root_dict[str(num+1)] = string.ascii_lowercase[num]

      # asking user for a three digit number
      sequence_to_convert = raw_input('Enter three digit number n')

      # storing all possible permutations from the three digit number
      first_permutation = sequence_to_convert[0]
      second_permutation = sequence_to_convert[1]
      third_permutation = sequence_to_convert[2]
      fourth_permutation = sequence_to_convert[0]+sequence_to_convert[1]
      fifth_permutation = sequence_to_convert[1]+sequence_to_convert[2]

      # checking if the permutations exist in the dict, if so print corresponding letters
      if first_permutation in root_dict and second_permutation in root_dict and third_permutation in root_dict:
      print root_dict[first_permutation]+root_dict[second_permutation]+root_dict[third_permutation]
      if first_permutation in root_dict and fifth_permutation in root_dict:
      print root_dict[first_permutation]+root_dict[fifth_permutation]
      if fourth_permutation in root_dict and third_permutation in root_dict:
      print root_dict[fourth_permutation]+root_dict[third_permutation]









      share|improve this question







      New contributor




      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Given a dictionary where 1:a , 2:b ... 26:z. I need to find all the possible letter combinations that can be formed from the three digits.



      Either each digit should translate to a letter individually or you can combine adjacent digits to check for a letter. You can't change the order of the digits. For example -



      121 translates to aba, au, la;



      151 translates to aea, oa;



      101 translates to ja;



      I was able to get this working but I feel my code is not very "pythonic". I am trying to figure out a more efficient & python-like solution for this problem.



      # creating the dict that has keys as digits and values as letters
      root_dict = {}
      for num in range(0,26):
      root_dict[str(num+1)] = string.ascii_lowercase[num]

      # asking user for a three digit number
      sequence_to_convert = raw_input('Enter three digit number n')

      # storing all possible permutations from the three digit number
      first_permutation = sequence_to_convert[0]
      second_permutation = sequence_to_convert[1]
      third_permutation = sequence_to_convert[2]
      fourth_permutation = sequence_to_convert[0]+sequence_to_convert[1]
      fifth_permutation = sequence_to_convert[1]+sequence_to_convert[2]

      # checking if the permutations exist in the dict, if so print corresponding letters
      if first_permutation in root_dict and second_permutation in root_dict and third_permutation in root_dict:
      print root_dict[first_permutation]+root_dict[second_permutation]+root_dict[third_permutation]
      if first_permutation in root_dict and fifth_permutation in root_dict:
      print root_dict[first_permutation]+root_dict[fifth_permutation]
      if fourth_permutation in root_dict and third_permutation in root_dict:
      print root_dict[fourth_permutation]+root_dict[third_permutation]






      python






      share|improve this question







      New contributor




      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Apr 2 at 4:30









      user168115user168115

      111




      111




      New contributor




      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user168115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          1












          $begingroup$

          First, Python 2 is going to be no longer supported in less than a year. If you are starting to learn Python now, learn Python 3. In your code the only differences are that print is a function now and no longer an expression (so you need ()) and that raw_input was renamed input (and the Python 2 input basically no longer exists).



          Your building of the root dictionary can be simplified a bit using a dictionary comprehension:



          from string import ascii_lowercase

          num_to_letter = {str(i): c for i, c in enumerate(ascii_lowercase, 1)}


          For the first three different permutations you can use tuple unpacking:



          first, second, third = sequence_to_convert


          Note that you are currently not validating if the user entered a valid string. The minimum you probably want is this:



          from string import digits
          digits = set(digits)

          sequence_to_convert = input('Enter three digit number n')
          if len(sequence_to_convert) != 3:
          raise ValueError("Entered sequence not the right length (3)")
          if not all(x in digits for x in sequence_to_convert):
          raise ValueError("Invalid characters in input (only digits allowed)")


          (A previous version of this answer used str.isdigit, but that unfortunately returns true for digitlike strings such as "¹"...)



          Your testing and printing can also be made a bit easier by putting the possible permutations into a list and iterating over it:



          permutations = [(first, second, third), (first, fifth), (fourth, third)]
          for permutation in permutations:
          if all(x in num_to_letter for x in permutation):
          print("".join(map(num_to_letter.get, permutation)))


          However, in the end you would probably want to make this more extendable (especially to strings longer than three). For that you would need a way to get all possible one or two letter combinations, and that is hard. It is probably doable with an algorithm similar to this one, but it might be worth it to ask a question on Stack Overflow about this.






          share|improve this answer











          $endgroup$













          • $begingroup$
            There is a pairwise generator in the Itertools recipes.
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:53










          • $begingroup$
            @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
            $endgroup$
            – Graipher
            Apr 2 at 15:54












          • $begingroup$
            itertools.chain(a_string, pairwise(a_string))
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:56








          • 1




            $begingroup$
            @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
            $endgroup$
            – Graipher
            Apr 2 at 15:58












          • $begingroup$
            Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
            $endgroup$
            – Austin Hastings
            Apr 2 at 16:01












          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.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          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
          });


          }
          });






          user168115 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216693%2fpythonic-code-to-convert-3-digit-number-into-all-possible-letter-combinations%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









          1












          $begingroup$

          First, Python 2 is going to be no longer supported in less than a year. If you are starting to learn Python now, learn Python 3. In your code the only differences are that print is a function now and no longer an expression (so you need ()) and that raw_input was renamed input (and the Python 2 input basically no longer exists).



          Your building of the root dictionary can be simplified a bit using a dictionary comprehension:



          from string import ascii_lowercase

          num_to_letter = {str(i): c for i, c in enumerate(ascii_lowercase, 1)}


          For the first three different permutations you can use tuple unpacking:



          first, second, third = sequence_to_convert


          Note that you are currently not validating if the user entered a valid string. The minimum you probably want is this:



          from string import digits
          digits = set(digits)

          sequence_to_convert = input('Enter three digit number n')
          if len(sequence_to_convert) != 3:
          raise ValueError("Entered sequence not the right length (3)")
          if not all(x in digits for x in sequence_to_convert):
          raise ValueError("Invalid characters in input (only digits allowed)")


          (A previous version of this answer used str.isdigit, but that unfortunately returns true for digitlike strings such as "¹"...)



          Your testing and printing can also be made a bit easier by putting the possible permutations into a list and iterating over it:



          permutations = [(first, second, third), (first, fifth), (fourth, third)]
          for permutation in permutations:
          if all(x in num_to_letter for x in permutation):
          print("".join(map(num_to_letter.get, permutation)))


          However, in the end you would probably want to make this more extendable (especially to strings longer than three). For that you would need a way to get all possible one or two letter combinations, and that is hard. It is probably doable with an algorithm similar to this one, but it might be worth it to ask a question on Stack Overflow about this.






          share|improve this answer











          $endgroup$













          • $begingroup$
            There is a pairwise generator in the Itertools recipes.
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:53










          • $begingroup$
            @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
            $endgroup$
            – Graipher
            Apr 2 at 15:54












          • $begingroup$
            itertools.chain(a_string, pairwise(a_string))
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:56








          • 1




            $begingroup$
            @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
            $endgroup$
            – Graipher
            Apr 2 at 15:58












          • $begingroup$
            Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
            $endgroup$
            – Austin Hastings
            Apr 2 at 16:01
















          1












          $begingroup$

          First, Python 2 is going to be no longer supported in less than a year. If you are starting to learn Python now, learn Python 3. In your code the only differences are that print is a function now and no longer an expression (so you need ()) and that raw_input was renamed input (and the Python 2 input basically no longer exists).



          Your building of the root dictionary can be simplified a bit using a dictionary comprehension:



          from string import ascii_lowercase

          num_to_letter = {str(i): c for i, c in enumerate(ascii_lowercase, 1)}


          For the first three different permutations you can use tuple unpacking:



          first, second, third = sequence_to_convert


          Note that you are currently not validating if the user entered a valid string. The minimum you probably want is this:



          from string import digits
          digits = set(digits)

          sequence_to_convert = input('Enter three digit number n')
          if len(sequence_to_convert) != 3:
          raise ValueError("Entered sequence not the right length (3)")
          if not all(x in digits for x in sequence_to_convert):
          raise ValueError("Invalid characters in input (only digits allowed)")


          (A previous version of this answer used str.isdigit, but that unfortunately returns true for digitlike strings such as "¹"...)



          Your testing and printing can also be made a bit easier by putting the possible permutations into a list and iterating over it:



          permutations = [(first, second, third), (first, fifth), (fourth, third)]
          for permutation in permutations:
          if all(x in num_to_letter for x in permutation):
          print("".join(map(num_to_letter.get, permutation)))


          However, in the end you would probably want to make this more extendable (especially to strings longer than three). For that you would need a way to get all possible one or two letter combinations, and that is hard. It is probably doable with an algorithm similar to this one, but it might be worth it to ask a question on Stack Overflow about this.






          share|improve this answer











          $endgroup$













          • $begingroup$
            There is a pairwise generator in the Itertools recipes.
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:53










          • $begingroup$
            @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
            $endgroup$
            – Graipher
            Apr 2 at 15:54












          • $begingroup$
            itertools.chain(a_string, pairwise(a_string))
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:56








          • 1




            $begingroup$
            @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
            $endgroup$
            – Graipher
            Apr 2 at 15:58












          • $begingroup$
            Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
            $endgroup$
            – Austin Hastings
            Apr 2 at 16:01














          1












          1








          1





          $begingroup$

          First, Python 2 is going to be no longer supported in less than a year. If you are starting to learn Python now, learn Python 3. In your code the only differences are that print is a function now and no longer an expression (so you need ()) and that raw_input was renamed input (and the Python 2 input basically no longer exists).



          Your building of the root dictionary can be simplified a bit using a dictionary comprehension:



          from string import ascii_lowercase

          num_to_letter = {str(i): c for i, c in enumerate(ascii_lowercase, 1)}


          For the first three different permutations you can use tuple unpacking:



          first, second, third = sequence_to_convert


          Note that you are currently not validating if the user entered a valid string. The minimum you probably want is this:



          from string import digits
          digits = set(digits)

          sequence_to_convert = input('Enter three digit number n')
          if len(sequence_to_convert) != 3:
          raise ValueError("Entered sequence not the right length (3)")
          if not all(x in digits for x in sequence_to_convert):
          raise ValueError("Invalid characters in input (only digits allowed)")


          (A previous version of this answer used str.isdigit, but that unfortunately returns true for digitlike strings such as "¹"...)



          Your testing and printing can also be made a bit easier by putting the possible permutations into a list and iterating over it:



          permutations = [(first, second, third), (first, fifth), (fourth, third)]
          for permutation in permutations:
          if all(x in num_to_letter for x in permutation):
          print("".join(map(num_to_letter.get, permutation)))


          However, in the end you would probably want to make this more extendable (especially to strings longer than three). For that you would need a way to get all possible one or two letter combinations, and that is hard. It is probably doable with an algorithm similar to this one, but it might be worth it to ask a question on Stack Overflow about this.






          share|improve this answer











          $endgroup$



          First, Python 2 is going to be no longer supported in less than a year. If you are starting to learn Python now, learn Python 3. In your code the only differences are that print is a function now and no longer an expression (so you need ()) and that raw_input was renamed input (and the Python 2 input basically no longer exists).



          Your building of the root dictionary can be simplified a bit using a dictionary comprehension:



          from string import ascii_lowercase

          num_to_letter = {str(i): c for i, c in enumerate(ascii_lowercase, 1)}


          For the first three different permutations you can use tuple unpacking:



          first, second, third = sequence_to_convert


          Note that you are currently not validating if the user entered a valid string. The minimum you probably want is this:



          from string import digits
          digits = set(digits)

          sequence_to_convert = input('Enter three digit number n')
          if len(sequence_to_convert) != 3:
          raise ValueError("Entered sequence not the right length (3)")
          if not all(x in digits for x in sequence_to_convert):
          raise ValueError("Invalid characters in input (only digits allowed)")


          (A previous version of this answer used str.isdigit, but that unfortunately returns true for digitlike strings such as "¹"...)



          Your testing and printing can also be made a bit easier by putting the possible permutations into a list and iterating over it:



          permutations = [(first, second, third), (first, fifth), (fourth, third)]
          for permutation in permutations:
          if all(x in num_to_letter for x in permutation):
          print("".join(map(num_to_letter.get, permutation)))


          However, in the end you would probably want to make this more extendable (especially to strings longer than three). For that you would need a way to get all possible one or two letter combinations, and that is hard. It is probably doable with an algorithm similar to this one, but it might be worth it to ask a question on Stack Overflow about this.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 2 at 14:32

























          answered Apr 2 at 8:38









          GraipherGraipher

          26.8k54396




          26.8k54396












          • $begingroup$
            There is a pairwise generator in the Itertools recipes.
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:53










          • $begingroup$
            @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
            $endgroup$
            – Graipher
            Apr 2 at 15:54












          • $begingroup$
            itertools.chain(a_string, pairwise(a_string))
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:56








          • 1




            $begingroup$
            @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
            $endgroup$
            – Graipher
            Apr 2 at 15:58












          • $begingroup$
            Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
            $endgroup$
            – Austin Hastings
            Apr 2 at 16:01


















          • $begingroup$
            There is a pairwise generator in the Itertools recipes.
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:53










          • $begingroup$
            @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
            $endgroup$
            – Graipher
            Apr 2 at 15:54












          • $begingroup$
            itertools.chain(a_string, pairwise(a_string))
            $endgroup$
            – Austin Hastings
            Apr 2 at 15:56








          • 1




            $begingroup$
            @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
            $endgroup$
            – Graipher
            Apr 2 at 15:58












          • $begingroup$
            Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
            $endgroup$
            – Austin Hastings
            Apr 2 at 16:01
















          $begingroup$
          There is a pairwise generator in the Itertools recipes.
          $endgroup$
          – Austin Hastings
          Apr 2 at 15:53




          $begingroup$
          There is a pairwise generator in the Itertools recipes.
          $endgroup$
          – Austin Hastings
          Apr 2 at 15:53












          $begingroup$
          @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
          $endgroup$
          – Graipher
          Apr 2 at 15:54






          $begingroup$
          @AustinHastings: I'm aware. But here you would need all partitions of a string into groups of one or two characters, not just the current and the following character.
          $endgroup$
          – Graipher
          Apr 2 at 15:54














          $begingroup$
          itertools.chain(a_string, pairwise(a_string))
          $endgroup$
          – Austin Hastings
          Apr 2 at 15:56






          $begingroup$
          itertools.chain(a_string, pairwise(a_string))
          $endgroup$
          – Austin Hastings
          Apr 2 at 15:56






          1




          1




          $begingroup$
          @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
          $endgroup$
          – Graipher
          Apr 2 at 15:58






          $begingroup$
          @AustinHastings: While this does work for the example with three characters (and so might be worth it to put it into an answer), it fails for more characters. For 1234, it is missing e.g. 12,3,4.
          $endgroup$
          – Graipher
          Apr 2 at 15:58














          $begingroup$
          Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
          $endgroup$
          – Austin Hastings
          Apr 2 at 16:01




          $begingroup$
          Ah, you're right. I was focused on pairing, and neglecting the "whole word" thing.
          $endgroup$
          – Austin Hastings
          Apr 2 at 16:01










          user168115 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          user168115 is a new contributor. Be nice, and check out our Code of Conduct.













          user168115 is a new contributor. Be nice, and check out our Code of Conduct.












          user168115 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review 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%2fcodereview.stackexchange.com%2fquestions%2f216693%2fpythonic-code-to-convert-3-digit-number-into-all-possible-letter-combinations%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

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...