Skip to content

Instantly share code, notes, and snippets.

@rvente
Created April 17, 2022 07:28
Show Gist options
  • Save rvente/a8baee476d37f63dc1141186533c7f9d to your computer and use it in GitHub Desktop.
Save rvente/a8baee476d37f63dc1141186533c7f9d to your computer and use it in GitHub Desktop.
import itertools
def decode_multi_tap(multitap_encoded: str):
if not multitap_encoded.replace(" ", "").isdecimal():
return ""
if "1" in multitap_encoded:
return ""
t9_map = {
"2" : "abc",
"3" : "def",
"4" : "ghi",
"5" : "jkl",
"6" : "mno",
"7" : "pqrs",
"8" : "tuv",
"9" : "wxyz",
}
output = ""
for root, occurences in itertools.groupby(multitap_encoded):
if root == " ":
continue
output += t9_map[root][len(list(occurences))-1]
return output
if __name__ == "__main__":
tests = [
"55544488833",
"5552884 44",
"55566688833",
]
for test in tests:
print(decode_multi_tap(test))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment