方法一:
a = 'abaoppuyqat11'
b = 'traoppuqat11'
d = ''
i = 0
c = 0
while c<len(a):
c += 1
if a[i:c] in b:
if len(a[i:c])>len(d):
d = a[i:c]
else:
i = c
print(d)
方法二:
a = 'abaoppuyqat11'
b = 'traoppuqat11'
c = []
for i in range(len(a)):
d = []
for j in b:
if a[i] ==j:
d.append(1)
else:
d.append(0)
c.append(d)
for i in range(1,len(a)):
for j in range(1,len(b)):
if c[i-1][j-1]>0 and c[i][j]>0:
c[i][j]=c[i-1][j-1]+1
a[[j for i in c for j in i].index(max([j for i in c for j in i]))//len(b)-max([j for i in c for j in i])+1:[j for i in c for j in i].index(max([j for i in c for j in i]))//len(b)+1]