a = [1, 3, 9, 8, 3, 4, 5]
b = [3, 4, 5, 7, 8]
matches = (i for i in range(len(b), 0, -1) if b[:i] == a[-i:])
i = next(matches, 0)
a + b[i:]
Pythonic way to merge two overlapping lists, preserving order