I'm making a script that reads a dictionary and picks out words that fit a search criteria. The code runs fine, but the problem is that it doesn't write any words to the file "wow" or print them out. The source for the dictionary is https://github.com/dwyl/english-words/blob/master/words.zip.
I've tried changing the opening of the file to "w+" instead of "a+" but it didn't make a difference. I checked if there just weren't any words that fitted the criteria but that isn't the issue.
listExample = [] #creates a list with open("words.txt") as f: #opens the "words" text file for line in f: listExample.append(line) x = 0 file = open("wow.txt","a+") #opens "wow" so I can save the right words to it while True: if x < 5000: # limits the search because I don't want to wait too long if len(listExample[x]) == 11: #this loop iterates through all words word = listExample[x] #if the words is 11 letters long lastLetter = word[10] print(x) if lastLetter == "t": #and the last letter is t file.write(word) #it writes the word to the file "wow" print("This word is cool!",word) #and prints it else: print(word) #or it just prints it x += 1 #iteration else: file.close() break #breaks after 5000 to keep it short It created the "wow" file but it is empty. How can I fix this issue?
file.write(word)len("adolescent")gives me 10