listA = [0, 1, 2, 1, 2, 1, 2, 3, 4, 5, 2, 1, 3, 4, 5, 2, 1, 6, 0]
listB = [0, 1, 2, 1, 2, 1, 0]

def get_repeated_seq(seq, start, length):
    ref = seq[start:start + length]
for pos in range(start + length, len(seq) - length):
    compare = seq[pos:pos + length]
if compare == ref:
    return pos, length
return False

def get_repeated_seqs(seq):
    reps = []
for size in reversed(list(range(2, len(seq) / 2))):
    for pos in range(0, len(seq) - size):
        rep = get_repeated_seq(seq, pos, size)
if rep:
    reps.append(rep)
return reps

def remove_repeated_seqs(seq, reps):
    for rep in reps:
        overlaps = False
for pos in range(rep[0], rep[0] + rep[1]):
    if seq[pos] == '*':
        overlaps = True
if not overlaps:
    for pos in range(rep[0], rep[0] + rep[1]):
        seq[pos] = '*'
out = []
for item in seq:
    if item != '*':
        out.append(item)
return out
reps = get_repeated_seqs(listB)
rem = remove_repeated_seqs(listB, reps)
print(rem == [0, 1, 2, 1, 0])
reps = get_repeated_seqs(listA)
rem = remove_repeated_seqs(listA, reps)
print(rem == [0, 1, 2, 3, 4, 5, 6, 0])
Удалить повторяющуюся последовательность целых чисел из списка в Python