Last active
May 21, 2026 13:47
-
-
Save adamamyl/2422f16e4694ad4f8824bbae5bc49283 to your computer and use it in GitHub Desktop.
t9 in python — pop what you want as an arg, get t9
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 | |
| import sys | |
| # T9 keyboard mapping | |
| T9_MAP = { | |
| 'a': '2', 'b': '2', 'c': '2', | |
| 'd': '3', 'e': '3', 'f': '3', | |
| 'g': '4', 'h': '4', 'i': '4', | |
| 'j': '5', 'k': '5', 'l': '5', | |
| 'm': '6', 'n': '6', 'o': '6', | |
| 'p': '7', 'q': '7', 'r': '7', 's': '7', | |
| 't': '8', 'u': '8', 'v': '8', | |
| 'w': '9', 'x': '9', 'y': '9', 'z': '9' | |
| } | |
| def to_t9(text): | |
| """Convert text to T9 number sequence.""" | |
| return ''.join(T9_MAP.get(char.lower(), char) for char in text) | |
| if __name__ == '__main__': | |
| if len(sys.argv) < 2: | |
| print("Usage: t9 <word1> [word2] [word3] ...") | |
| sys.exit(1) | |
| for word in sys.argv[1:]: | |
| print(to_t9(word)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment