我正在尝试查找段落中所有出现的单词,并且我希望它也能解决拼写错误。代码:
to_search="caterpillar"
search_here= "caterpillar are awesome animal catterpillar who like other humans but not other caterpilar"
#search_here has the word caterpillar repeated but with spelling mistakes
s= SequenceMatcher(None, to_search, search_here).get_matching_blocks()
print(s)
#Output : [Match(a=0, b=0, size=11), Match(a=3, b=69, size=0)]
#Expected: [Match(a=0, b=0, size=11), Match(a=0, b=32, size=11), Match(a=0, b=81, size=11)]
Difflib get_matching_blocks 仅检测 search_here 字符串中“caterpillar”的第一个实例。我希望它给我所有紧密匹配的块的输出,即它应该识别“卡特彼勒”、“卡特彼勒”和“卡特彼勒”
我怎么解决这个问题?