-2
所以我打算從拼寫錯誤的示例文件中打印出單詞,我似乎無法弄清楚如何在2個列表中循環。下面的代碼:(上面只是一個輔助功能),dict.txt是每一個可能的字的只是一個長長的清單打印Python中拼寫錯誤的文件中的單詞
def cleanWords(wlist):
ret=[]
for word in wlist:
cleanword = word.strip('?.,;:!\'-"\n()')
ret.append(cleanword.lower())
return ret
f = open('dict.txt', 'r')
lines = f.readlines()
cleanlistdic = cleanWords(lines)
inword = raw_input("Enter a file name: ")
g = open(inword, 'r')
lines2 = g.readlines()
cleanlistfile = cleanWords(lines2)
# this part is where i get stuck
for line in cleanlistfile:
for j in cleanlistdic:
if line not in cleanlistdic:
print line
而現在它僅僅是打印所有的測試文件中的單詞。有什麼建議麼?對於cleanlistfile中的行,請使用 –
: if(line not in cleanlistdict): print line –