diff options
author | Albert Tan <s22505@ykpaoschool.cn> | 2023-04-13 20:44:27 +0800 |
---|---|---|
committer | Albert Tan <s22505@ykpaoschool.cn> | 2023-04-13 20:44:27 +0800 |
commit | eff525fd045ca87652b757d247588306802975dd (patch) | |
tree | 474a88f49515ef73566ac0c930778646938b1e6b /possible_words_final.py | |
download | albertscripts-eff525fd045ca87652b757d247588306802975dd.tar.gz albertscripts-eff525fd045ca87652b757d247588306802975dd.zip |
Squish Albert
Diffstat (limited to 'possible_words_final.py')
-rw-r--r-- | possible_words_final.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/possible_words_final.py b/possible_words_final.py new file mode 100644 index 0000000..42409d7 --- /dev/null +++ b/possible_words_final.py @@ -0,0 +1,70 @@ +print(''' +Find possible word combinations here! +You can search in the following provided word lists: + + List Name File Name Size + --------------------------- --------- ------------ +- New General Service List ngs.txt 2853 Words +- New Dolch List ndl.txt 3462 Words +- Incoherency.co.uk Countdown icd.txt 101484 Words +- Mac /usr/share/dict/words wds.txt 235886 Words +- Collins Scrabble Dictionary csd.txt 279496 Words +- Infochimps Word List iwl.txt 370105 Words +- All words from the above all.txt 458885 Words + +To choose from the above lists, enter the file name provided; +If you have your own list of words in .txt, enter the full directory. +Enter the file name or directory: ''') + +letters = [] +valids = [] +n = 0 + + +def dfs(cur_str, used): + if cur_str in words: + valids.append(cur_str) + if len(cur_str) == n: + return + for i in range(n): + if used[i]: + continue + used[i] = True + dfs(cur_str + letters[i], used) + used[i] = False + + +try: + with open(input().split(".")[0] + ".txt") as f: + words = set(word.strip() for word in f) + + letters = list(input("\nEnter letters to be checked; do not include spaces or any other characters. \n").lower()) + n = len(letters) + valids = [] + + if n > 10: + print("\nIt might take a good while to run. Please wait...") + dfs("", [False] * n) + print() + + if valids[0] == "": + valids.pop(0) + if len(valids) == 0: + print("Nothing found. Try to use a different word list, or check your input. ") + + valids = sorted(set(valids), key=len, reverse=True) + flag5 = False + flag3 = False + for valid in valids: + if len(valid) == 5 and not flag5: + input("Press \"ENTER\" to show words with less than 6 letters") + flag5 = True + elif len(valid) == 3 and not flag3: + input("Press \"ENTER\" to show words with less than 4 letters") + flag3 = True + print(valid) + +except KeyboardInterrupt: + print("\nProgram Stopped") +except BaseException as e: + print("Error:", e) |