ans1 = [1, 2, 3, 4, 5, 2, 1]
ans2 = [5, 2, 3, 4, 5, 3, 1]
count = 0
answer = False

for i in range(len(ans1)):
    if ans1[i] == ans2[i]:
        count += 1
        if count >= 4:
            answer = True
    else:
        count = 0
        
print(answer)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: