Last active
June 23, 2025 18:41
-
-
Save Lenochxd/a001b1dc69d2addfd019c2465e69f920 to your computer and use it in GitHub Desktop.
T9 string to text and vice versa
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
t9_mapping = { | |
'2': 'abc', | |
'3': 'def', | |
'4': 'ghi', | |
'5': 'jkl', | |
'6': 'mno', | |
'7': 'pqrs', | |
'8': 'tuv', | |
'9': 'wxyz', | |
'0': ' ' | |
} | |
input_string = input("Enter T9 input: ").split() | |
text = "" | |
for char in input_string: | |
if char[0] in t9_mapping: | |
text += t9_mapping[char[0]][len(char) - 1] # Get the character based on the number of presses | |
else: | |
text += char | |
print() | |
print(text) |
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
t9_mapping = { | |
'abc': '2', | |
'def': '3', | |
'ghi': '4', | |
'jkl': '5', | |
'mno': '6', | |
'pqrs': '7', | |
'tuv': '8', | |
'wxyz': '9', | |
' ': '0' | |
} | |
input_string = input("Enter text input: ") | |
output = "" | |
for char in input_string: | |
for key, value in t9_mapping.items(): | |
if char in key: | |
output += value * (key.index(char) + 1) + " " # Repeat the number based on the position of the character | |
break | |
else: | |
output += char # If character is not found in mapping, add it as is | |
print() | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment