发布网友 发布时间:2022-04-23 16:38
共1个回答
热心网友 时间:2022-04-18 15:56
把较低的mismatch用字典保存一下,就好了。如:
def match(s1,s2):
length = len(s2)result = ""resultMissmatchCount=lengthseqdict={}for index,s in enumerate(s1[:-length]):
missmatch = 0
for j,k in zip(s1[index:index+length],s2): #[(s1[0],s2[0]),(s1[1],s2[1]),...]
if j!=k:
missmatch += 1
if missmatch <= resultMissmatchCount:
seqdict[missmatch]=s1[index:index+length]
resultMissmatchCount = missmatch
minkey=min(seqdict.keys())result = seqdict[minkey]return result