-
Notifications
You must be signed in to change notification settings - Fork 0
/
freqFilter.py
56 lines (48 loc) · 1.5 KB
/
freqFilter.py
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
import random
import numpy as np
# https://www.kaggle.com/rtatman/english-word-frequency
def writeFreqToList():
with open("D:\\Programming\\wordleSolver\\freqDb.txt") as file:
lines = file.read()
lines = lines.split('\n')
words = []
for line in lines:
line = line.split(': ')
words.append(line[0])
return words
def sortByFreq(words):
for i in range(len(words)):
words[i] = "".join(words[i])
values = []
freqList = writeFreqToList()
for i in range(len(words)):
if words[i] in freqList:
values.append(freqList.index(words[i]))
words = np.array(words)
values = np.array(values)
indexes = values.argsort()
words = words[indexes]
values = values[indexes]
return words
def getCommonWord(words):
freqs = sortByFreq(words)
best = None
second = None
for j in range(len(freqs)):
for i in range(len(words)):
if freqs[j] == words[i] and best is not None:
second = words[i]
if freqs[j] == words[i] and best is None:
best = words[i]
if best is not None and second is not None:
break
if best is None and len(words) > 1:
return words[0], words[1]
elif best is not None and len(words) == 1:
return best, None
elif best is None and len(words) == 1:
return words[0], None
elif best is not None and second is not None:
return best, second
else:
return words[0], None