Created
September 6, 2026 03:52
-
-
Save wonderb0lt/5760ecce035eabb1eed0e2b56d50833b to your computer and use it in GitHub Desktop.
T9 key combinations: If you enter the keys of REAL_TEST into a T9 keyboard, which other words would be valid under the same keystrokes?
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
| from functools import partial | |
| from itertools import product | |
| # pip install pyenchant | |
| from enchant import Dict # I'm on Windows so I don't have a native dictionary sryyyy | |
| REAL_TEST = 'selected' # rejected as expected, also selectee | |
| REAL_WORDS = Dict('en_US') | |
| LETTERTOKEY = { | |
| 'abc': 2, | |
| 'def': 3, | |
| 'ghi': 4, | |
| 'jkl': 5, | |
| 'mno': 6, | |
| 'pqrs': 7, | |
| 'tuv': 8, | |
| 'wxyz': 9, | |
| } | |
| KEYTOLETTER = {v: k for k, v in LETTERTOKEY.items()} | |
| def find_key(letter): | |
| for key in LETTERTOKEY.keys(): | |
| if letter in key: | |
| return LETTERTOKEY[key] | |
| return -1 | |
| def find_letter(key_input): | |
| for key in KEYTOLETTER.keys(): | |
| if key == key_input: | |
| return KEYTOLETTER[key] | |
| def explode(s): | |
| return list(s) | |
| source = REAL_TEST | |
| source_keys = list(map(find_key, REAL_TEST)) | |
| possible_letters = [explode(key_letters) for key_letters in map(find_letter, source_keys)] # list of all possible letters per key, as a list itself | |
| combinations = product(*possible_letters) | |
| for combination in combinations: | |
| comb_s = ''.join(combination) | |
| if REAL_WORDS.check(comb_s) and comb_s != source: | |
| print(comb_s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment