Skip to content

Instantly share code, notes, and snippets.

@emhart
Last active October 6, 2018 00:10
Show Gist options
  • Save emhart/e5417c440238475a85e093de7b1690cc to your computer and use it in GitHub Desktop.
Save emhart/e5417c440238475a85e093de7b1690cc to your computer and use it in GitHub Desktop.
sonder_keypad
num2letter = {"2":"abc", "3":"def", "4":"ghi", "5":"jkl", "6":"mno",
"7":"pqrs", "8":"tuv", "9":"wxyz"}
def keys2letters(key_presses):
results = [x for x in num2letter[key_presses[0]]]
if len(key_presses) <= 1:
return(results)
else:
for x in key_presses[1:]:
new_list = [x for x in num2letter[x]]
results = [i+j for i in results for j in new_list]
return(results)
# test cases
keys2letters('2')
keys2letters('23')
keys2letters('2345')
keys2letters('222')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment