Last active
October 6, 2018 00:10
-
-
Save emhart/e5417c440238475a85e093de7b1690cc to your computer and use it in GitHub Desktop.
sonder_keypad
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
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