我使用https://norvig.com/spell-correct.html查找拼写错误
如何查找和替换句子中拼写错误的单词。
到目前为止的努力:
sentences = "This sntence cntins errors. This sentence has to be corrcted."
list_string = sentences.split(' ')
for word in list_string:
print(correction(word))
输出:
this
sentence
contains
error
this
sentence
has
to
be
corrected.
预期输出:
This <<sntence>> sentence <<cntins>> contains errors. This sentence has to be <<corrcted>> corrected.
能够使用https://stackoverflow.com/questions/48123861/spelling-mistakes-pyenchant.来实现它,如何找到并替换拼写错误的单词为原始文本,同时将拼写错误的单词保留在<< >>
内答案 0 :(得分:1)
尝试str.join
生成器:
print(' '.join('<<'+i+'>>'+' %s'%correction(i) if correction(i) != i else i for i in sentences.split()))