Skip to content

Instantly share code, notes, and snippets.

@KorbenC
Last active December 31, 2015 18:39
Show Gist options
  • Save KorbenC/8028304 to your computer and use it in GitHub Desktop.
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
#!/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