Last active
August 29, 2015 14:24
-
-
Save debetimi/34c1351d62ebba351638 to your computer and use it in GitHub Desktop.
Returns mnemonics for a phone number
This file contains 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
pad = {0: ['0'], 1: ['1'], 2: ['A', 'B', 'C'], 3: ['D', 'E', 'F'], 4: ['G', 'H', 'I'],\ | |
5: ['J', 'K', 'L'], 6:['M', 'N', 'O'], 7:['P', 'Q','R', 'S'], 8: ['T', 'U', 'V'],\ | |
9: ['W', 'X', 'Y', 'Z']} | |
def list_mnemonics(number): | |
a = set() | |
if number == '': | |
a.add('') | |
return a | |
chars = pad[int(number[0])] | |
for substring in list_mnemonics(number[1:]): | |
for char in chars: | |
a.add(char + substring) | |
return list(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment