Last active
July 23, 2024 15:30
-
-
Save bugbrekr/891a0a58ef05b211a8027c0c2c582a5a to your computer and use it in GitHub Desktop.
A much more simpler and efficient word unjumbler
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
| """ | |
| A very stupid Word Unjumbler. V2. | |
| Author: BugBrekr | |
| Date: 23/07/2024 | |
| Requires words_alpha.txt. | |
| Available at: https://github.com/dwyl/english-words/blob/master/words_alpha.txt | |
| """ | |
| import time | |
| with open("words_alpha.txt", encoding="utf-8") as f: | |
| dictionary = [i.strip() for i in f.readlines()] | |
| def _get_unique_only(lst): | |
| unique_lst = [] | |
| for c in lst: | |
| if c not in unique_lst: | |
| unique_lst.append(c) | |
| unique_lst.sort() | |
| return unique_lst | |
| def unjumble(j): | |
| """Pylint won't leave me alone.""" | |
| ltrs = _get_unique_only(list(j)) | |
| m = [] | |
| for w in dictionary: | |
| if len(w) != len(j): | |
| continue | |
| tltrs = _get_unique_only(w) | |
| if ltrs == tltrs: | |
| m.append(w) | |
| return m | |
| while True: | |
| jumbled_word = input("Jumbled word: ").strip().lower() | |
| st = time.time() | |
| matches = unjumble(jumbled_word) | |
| dur = time.time()-st | |
| print(f'Found {len(matches)} words in {dur:.2f}s:') | |
| for i, word in enumerate(matches): | |
| print(f'{i+1}: '+word) | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment