 |
|
juny1998
V2EX member #624110, joined on 2023-04-14 13:35:09 +08:00
|
juny1998's recent replies
def extract_common_substrings(str1, str2):
common_substrings = []
for i in range(len(str1)):
for j in range(i + 4, len(str1) + 1):
substring = str1[i:j]
if substring in str2 and len(substring) >= 4:
common_substrings.append(substring)
return common_substrings
# 例子
A = "我今天特别开心啊,因为今天是个好日子,我中了 500 万彩票。"
B = "今天不是个好日子,因为邻居中了 500 万彩票,我今天不开心。"
common_substrings = extract_common_substrings(A, B)
print(common_substrings)