📜  python 查找字符串是否具有公共子字符串 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:29.450000             🧑  作者: Mango

代码示例1
# credit to the Stack Overflow user in the source link

from difflib import SequenceMatcher

string1 = "apple pie available"
string2 = "come have some apple pies"

match = SequenceMatcher(None, string1, string2).find_longest_match(0, len(string1), 0, len(string2))

print(match)  # -> Match(a=0, b=15, size=9)
print(string1[match.a: match.a + match.size])  # -> apple pie
print(string2[match.b: match.b + match.size])  # -> apple pie