其实应该是一个很简单的递归,奈何算法太久没练…只能写成下面这个丑样子,emmm而且找的还是end position…将就一下吧
def find_sublist(lis:list,sublis:list,i=0,j=0):
'''
recursion, find the **end** index of the sub-list in the list
if multiple sub-list, calculate the first one
if not the sub-list, there will be an IndexError
'''
if lis[i] == sublis[j]:
if j == len(sublis) - 1:
return i
else:
return find_sublist(lis,sublis,i+1,j+1)
else:
return find_sublist(lis,sublis,i+1,0)