Skip to content

Instantly share code, notes, and snippets.

@debetimi
Last active August 29, 2015 14:24
Show Gist options
  • Save debetimi/34c1351d62ebba351638 to your computer and use it in GitHub Desktop.
Save debetimi/34c1351d62ebba351638 to your computer and use it in GitHub Desktop.
Returns mnemonics for a phone number
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