Last active
December 31, 2015 18:39
-
-
Save KorbenC/8028304 to your computer and use it in GitHub Desktop.
given a digit number print all of the possible strings you can make with it using the corresponding letters on the numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| digit_map = { | |
| '2': 'abc', | |
| '3': 'def', | |
| '4': 'ghi', | |
| '5': 'jkl', | |
| '6': 'mno', | |
| '7': 'pqrs', | |
| '8': 'tuv', | |
| '9': 'wxyz', | |
| } | |
| def word_numbers(input): | |
| input = str(input) | |
| ret = [''] | |
| for char in input: | |
| letters = digit_map.get(char, '') | |
| ret = [prefix+letter for prefix in ret for letter in letters] | |
| return ret | |
| def main(): | |
| print word_numbers(23) | |
| if __name__ == '__main__': | |
| status = main() | |
| sys.exit(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment