Skip to content

Instantly share code, notes, and snippets.

@maxmarchuk
Created May 31, 2016 22:48
Show Gist options
  • Save maxmarchuk/308ebce875eb7cc23fa3b46c3a57b2d7 to your computer and use it in GitHub Desktop.
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.
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