-
Notifications
You must be signed in to change notification settings - Fork 0
/
unscramble.py
53 lines (45 loc) · 1.25 KB
/
unscramble.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
def RemoveFromList(thelist, val):
return [value for value in thelist if value != val]
def GetDic():
try:
dicopen = open("wordlist.txt", "r")
dicraw = dicopen.read()
dicopen.close()
diclist = dicraw.split("\n")
diclist = RemoveFromList(diclist, '')
return diclist
except FileNotFoundError:
print("No Dictionary!")
return
def Word2Vect(word):
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
v = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
w = word.lower()
wl = list(w)
for i in range(0, len(wl)):
if wl[i] in l:
ind = l.index(wl[i])
v[ind] += 1
return v
def Vect2Int(vect):
pv = 0
f = 0
for i in range(0, len(vect)):
wip = (vect[i]*(2**pv))
f += wip
pv += 4
return f
def Ints2Dic(dic):
d = {}
for i in range(0, len(dic)):
v = Word2Vect(dic[i])
Int = Vect2Int(v)
if Int in d:
tat = d.get(Int)
tat.append(dic[i])
d[Int] = tat
elif Int not in d:
d[Int] = [dic[i]]
return d