-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionsFile.py
More file actions
75 lines (60 loc) · 2.2 KB
/
FunctionsFile.py
File metadata and controls
75 lines (60 loc) · 2.2 KB
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
71
72
73
74
75
import operator
def checker(letters, word):
for letter in letters:
if letter not in word: #If the letter is not in the word i.e. 'A' is not in 'TIGER'
return False
return True
def questionMark(input):
global l
global amount
amount=0
l=list(input)
print(l)
for letter in l:
print(letter)
if letter=='?':
amount+=1
while l.count("?")!=0:
l.pop(l.index(letter))
return l
def sort(x, perfect, letters, results, backup):
sorted_x = sorted(x.items(), key=operator.itemgetter(1), reverse=True)
for i in sorted_x:
wordFixed=i[0]
correctLength=i[1]
wordFixed = wordFixed[:-1]
if len(wordFixed)>2:
'''If the length of the word is equal to or smaller than
the length of the input + the amount of blank tiles'''
if amount>0:
if checker(letters, wordFixed) and len(wordFixed)<=(len(letters)+amount) and \
\
wordFixed[0]==final(backup, wordFixed)[0] and \
wordFixed[len(wordFixed)-1]==final(backup, wordFixed)[1]:
perfect.append(wordFixed) #If all the letters are in the word,
results[wordFixed] = i[1] #but there are other letters as well
elif amount==0:
'''If the length of the word is the same
as the amount of correct characters in the word
And if start and end match up'''
if len(wordFixed)==(correctLength + final(backup, wordFixed)[2]) and \
\
wordFixed[0]==final(backup, wordFixed)[0] and \
wordFixed[len(wordFixed) - 1]==final(backup, wordFixed)[1]:
perfect.append(wordFixed)
results[wordFixed]=i[1] #Appends the word and it's char length to a dict.
#return sorted_x
def final(inputWord, w):
if len(inputWord)>=2:
start=inputWord[1]
start=start[:-1] #To get rid of the comma
x=1
else:
start=w[0]
x=0
if len(inputWord)==3:
end=inputWord[2]
x+=1
else:
end=w[len(w)-1]
return start, end, x