I have the following program which is supposed to loop through all of the different letter shift possibilities and match them with lines in a text file dictionary.
def autoDecode(userString):
scores = [0 for i in range(25)]
sentenceArray = decode(userString)
score = 0
# loop over each sentence in the sentence array
with open('engmix.txt') as dictionary:
for sentence in sentenceArray:
sentence = sentence.split(" ")
sentencePos = 1
for word in sentence:
word = word.lower()
for entry in dictionary:
if word == entry.strip():
score += 1
scores[sentencePos] = score
score = 0
sentencePos = 0
dictionary.seek(0)
print(scores)
print("The sentence is likely to be", sentenceArray[sentencePos])
Now, I know this isn't the most efficient method but I'm trying to make it readable for someone else before moving to efficiency. However, the line
if word == entry.strip()
isn't registering as true when two words are the same meaning the scores loop is empty at the end.
Any ideas?