小编jad*_*jad的帖子

如何打印位于txt文件中的不正确的字词?

我有这段代码只打印错误单词的行号.我希望它打印txt文件中不正确的单词的亚麻布.我可以修改此代码来做到这一点吗?

# text1 is my incorrect words
# words is my text file where my incorrect word are in 

from collections import defaultdict
d = defaultdict(list)
for lineno, word in enumerate(text1):
    d[word].append(lineno)
print(d)
Run Code Online (Sandbox Code Playgroud)

香港专业教育学院现在已经完成了这个,但是这会打印出它所在的角色,就像这个词的位置而不是线条.这是代码

import sys
import string

text = []
infile = open(sys.argv[1], 'r').read()
for punct in string.punctuation:
    infile = infile.replace(punct, "")
    text = infile.split()

dict = open(sys.argv[2], 'r').read()
dictset = []
dictset = dict.split()

words = []
words = list(set(text) - set(dictset))
words = [text.lower() for text in …
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
285
查看次数

标签 统计

python ×1