Created
May 31, 2016 22:48
-
-
Save maxmarchuk/308ebce875eb7cc23fa3b46c3a57b2d7 to your computer and use it in GitHub Desktop.
A simple Python script to get the number of key presses that would be required to type a certain phrase on a T9-style phone keyboard.
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
def presses(phrase): | |
mapping = { | |
"*": "*", | |
"#": "#", | |
0: " 0", | |
1: "1", | |
2: "ABC2", | |
3: "DEF3", | |
4: "GHI4", | |
5: "JKL5", | |
6: "MNO6", | |
7: "PQRS7", | |
8: "TUV8", | |
9: "WXYZ9", | |
} | |
count_map = {} | |
for k in mapping.keys(): | |
for c in mapping[k]: | |
count_map[c] = mapping[k].index(c) + 1 | |
clicks = 0 | |
for character in phrase: | |
clicks += count_map[character.upper()] | |
return clicks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment