Skip to content

Instantly share code, notes, and snippets.

@spacelatte
Created September 25, 2022 11:50
Show Gist options
  • Save spacelatte/13c8fc9483f14d4c70085e0319d9a9b5 to your computer and use it in GitHub Desktop.
Save spacelatte/13c8fc9483f14d4c70085e0319d9a9b5 to your computer and use it in GitHub Desktop.
#t9 #keyboard #phone #converter #python3 #python #py
#!/usr/bin/env python3
"""
1 = abc
2 = def
3 = ghi
4 = jkl
5 = mno
6 = pqr
7 = stu
8 = vwx
9 = yz
0 = ' .,' # space dot comma
"""
alphabet = " .,abcdefghijklmnopqrstuvwxyz"
# |^--^--^--^--^--^--^--^--^--^-|
# | 0 1 2 3 4 5 6 7 8 9|
index = lambda char: alphabet.index(char)
lookup = lambda char: str(index(char)//3) * (1+index(char)%3)
resolve = lambda string: " ".join(lookup(char) for char in string)
resolve("space latte")
#> '7 6 1 111 22 0 444 1 77 77 22'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment