When
#validCandidateList += word
stays commented, program runs fine. When this line is uncommented, program starts printing out some repeated line over and over again.2. As you can seeI am sorry, I just had to apply .lowercase() to the word. Dictionary contains some uppercase letters too.sorted(set(eWord))
is sorted, so for example if I input "dog", or "good", it creates same sorted list of letters -['d', 'g', 'o']
, but the program does not print the out the wordgood
when input isdog
, even though you can confirm that both words exist in the dictionary, by inputting them in a single run of program, separated by spaces, or inputting one of the words in different program runs.Please help.
import os
cwd = os.path.dirname(os.path.abspath(__file__))
fname = "\\dictionary.txt"
file = open(cwd + fname, "r")
readFile = file.read()
dictionary = readFile.split() #list type variable with more than 400 000 words.
input = input("Input your list of words, separated by spaces: ")
inputList = input.split()
validCandidateList = inputList
for eWord in dictionary:
for word in inputList:
if sorted(set(eWord)) == sorted(set(word)):
print(word, ": ",eWord)
#validCandidateList += word
print(validCandidateList)