summaryrefslogtreecommitdiff
path: root/possible_words_final.py
blob: 42409d77157b97d16365069f444f816ef09c4a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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)