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)