【发布时间】:2019-07-15 09:48:31
【问题描述】:
我有这样的字符串:
strA = "Today is hot. My dog love hot dog, milk, and candy."
strB = "hot dog and bread"
我希望输出字符串像:
"Today is hot. My dog love hot dog and bread, milk, and candy."
不是
"Today is hot dog and bread. My dog love hot dog, milk, and candy."
我尝试使用str.find()
但不合适。
if strA.find(strB) != -1:
x = strA.find(strB)
listA = list(strA)
listA.insert(x, strB)
output = ''.join(listA)
【问题讨论】:
-
合并规则是什么?
-
@KlausD。我更新我的问题,谢谢!它想要合并最相似的句子。
-
@FurryBear,好的,
"Today is hot. My dog love hot dog, milk. But my cat loves hot dog and fish"的预期输出是什么? -
这个问题和生物信息学中的sequence alignment非常相似。目标是在允许错误的同时找到最接近的匹配子字符串。然后你可以使用这个匹配来插入/替换文本
标签: python