Created
September 25, 2022 11:50
-
-
Save spacelatte/13c8fc9483f14d4c70085e0319d9a9b5 to your computer and use it in GitHub Desktop.
#t9 #keyboard #phone #converter #python3 #python #py
This file contains hidden or 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
#!/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