我正在编写一个拼写检查功能,我正在使用两个文本文件:一个拼写错误的文本和一个包含字典中一堆单词的文本文件。我已将拼写错误单词的文本转换为字符串列表,并将包含字典单词的文本文件转换为单词列表。现在我需要查看拼写错误列表中的单词是否在我的字典单词列表中。
def spellCheck():
checkFile=input('Enter file name: ')
inFile=open(checkFile,'r')
# This separates my original text file into a list like this
# [['It','was','the','besst','of','times,'],
# ['it','was','teh','worst','of','times']]
separate=[]
for line in inFile:
separate.append(line.split())
# This opens my list of words from the dictionary and
# turns it into a list of the words.
wordFile=open('words.txt','r')
words=wordFile.read()
wordList=(list(words.split()))
wordFile.close()
# I need this newList to be a list of the correctly spelled words
# in my separate[] list and if the word isn't spelled correctly
# it will go into another if statement...
newList=[]
for word in separate:
if word in wordList:
newList.append(word)
return newList