句子中的拼写更正

Spelling correction in sentences

我用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.

能够使用 实现如何在 << >>

中找到拼错的单词并将其替换为原始文本

尝试 str.join 生成器:

print(' '.join('<<'+i+'>>'+' %s'%correction(i) if correction(i) != i else i for i in sentences.split()))