with open('index.txt', 'r') as f:
indexList = f.read().split('\n')
indexList = [i.rstrip() for i in indexList]
errorList = []
with open('in.txt', 'r') as f:
content = f.read()
content = [i.rstrip().lower() for i in content]
article = ' '
for i in content:
if i >= 'a' and i <= 'z':
article += i
else:
article += ' '
for word in article.split():
if word not in indexList:
errorList.append(word)
errorList.sort()
with open('error.txt', 'w') as f:
for error in errorList:
f.write(error + 'n')
注意缩进:
with open('index.txt', 'r') as f:
indexList = f.read().split('\n')
indexList = [i.rstrip() for i in indexList]
errorList = []
with open('in.txt', 'r') as f:
content = f.read()
content = [i.rstrip().lower() for i in content]
article = ' '
for i in content:
if i >= 'a' and i <= 'z':
article += i
else:
article += ' '
for word in article.split():
if word not in indexList:
errorList.append(word)
errorList.sort()
with open('error.txt', 'w') as f:
for error in errorList:
f.write(error + '\n')