Finding sequences in two arrays
This should work
def findUntilNotSame(array1,array2):
    resultPos = 0
    for i in range (len(array1)):
        if(i &lt; len(array2)):
            if(array1[i] != array2[i]):
                break
            resultPos += 1
    return resultPos

# find the length of same value
def findStartSame(array1,array2):
    for i in range(len(array1)):
        if array1[i] in array2:
            return [i,array2.index(array1[i])]

# find the solution one time
def findStartAndLength(array1,array2):

    start = findStartSame(array1,array2)
    start1 = start[0]
    start2 = start[1]
    length = findUntilNotSame(array1[start1:],array2[start2:])
    return [[start1,length],[start2,length]]

def updateAnswer(finalOrigin):
    finalResult=finalOrigin
    for i in range (len(finalResult)):
        if i != 0:
            finalResult[i][0][0] += finalResult[i-1][0][0] + finalResult[i-1][0][1]
            finalResult[i][1][0] += finalResult[i-1][1][0] + finalResult[i-1][1][1]
    return finalResult

def algorithm(array1,array2):
    i, j = 0, 0
    finalResult = []
    while(i&lt;len(array1) or j&lt;len(array2)):
        array1now = array1[i:]
        array2now = array2[j:]
        if(any(item in array1now for item in array2now)):
            result = findStartAndLength(array1now,array2now)
            finalResult.append(result)
            nextStart1 = result[0][0] + result[0][1]
            i += nextStart1
            nextStart2 = result[1][0] + result[1][1]
            j += nextStart2
        else:
            i += 1
            j += 1
    return updateAnswer(finalResult)