修改了几行,增加了几行
如果找不到任何子字符串,则修改是answer=“NULL”的默认返回。在
已添加
继续搜索,直到得到NULL并存储到列表def longestSubstringFinder(string1, string2):
answer = "NULL"
len1, len2 = len(string1), len(string2)
for i in range(len1):
match = ""
for j in range(len2):
if (i + j < len1 and string1[i + j] == string2[j]):
match += string2[j]
else:
if (len(match) > len(answer)): answer = match
match = ""
return answer
mylist = []
def call():
s1 = 'Today is a good day, it is a good idea to have a walk.'
s2 = 'Yesterday was not a good day, but today is good, shall we have a walk?'
s1 = s1.lower()
s2 = s2.lower()
x = longestSubstringFinder(s2,s1)
while(longestSubstringFinder(s2,s1) != "NULL"):
x = longestSubstringFinder(s2,s1)
print(x)
mylist.append(x)
s2 = s2.replace(x,' ')
call()
print ('[%s]' % ','.join(map(str, mylist)))
输出
^{pr2}$
你的产出差异common = ['today is', 'a good day', 'is', 'a good', 'have a walk']
你对秒的期望是“错误的,正如你在s2中看到的,只有一个是”