在 Python 中,你可以使用模块 pyenchant
来查找 word 中的错别字。
首先,你需要安装 pyenchant
模块:
pipinstall pyenchant
然后,你可以使用下面的代码来查找 word 中的错别字:
import enchant# 读取 word 文件
with open("word.txt", "r") as f:
text = f.read()
# 创建拼写检查器
spell_checker = enchant.Dict("en_US")
# 查找错别字
mispelled_words = []
for word in text.split():
if not spell_checker.check(word):
mispelled_words.append(word)
print(mispelled_words)
这段代码会打印出 word 中的所有错别字。你也可以使用 enchant.Dict("zh_CN")
来检查中文文本中的拼写错误。