我需要創建一個讀取文本文件並創建拼寫錯誤的單詞的字典的函數。 這是我迄今爲止我如何完成我的拼寫檢查代碼?
def spellCheck(textFileName):
file=open("words.txt","r")
wordsList = file.read()
print wordsList
file.close()
file=open(textFileName, "r")
wordsToCheck = file.read()
print wordsToCheck
file.close()
# The next line creates the dictionary
# This dictionary will have the word that has been spelt wrong as the key and the number of times it has been spelt wrong as the value
spellingErrors = dict= {'words', wordsToCheck}
,我需要:
# Loop through the wordsToCheck list
# Change the current word into lower case
# If the current word does not exist in the wordsList then
# Check if the word already exists in the spellingErrors dictionary
# If it does not exist than add it to the dictionary with the initial value of 1.
# If it does exist in the dictionary then increase the value by 1
# Return the dictionary
所以,實際的算法,到目前爲止你嘗試過了什麼? – learner
本地化太大。再次。 http://stackoverflow.com/questions/13573552/can-anyone-help-me-with-my-spell-check-code – Yandros