fork download
  1. import heapq
  2.  
  3. def combine(l1, l2):
  4. for i in reversed(range(min(map(len, (l1, l2))))):
  5. if l1[i] == l2[i]:
  6. return l2[:(end := i + 1)] + list(heapq.merge(l1[end:], l2[end:]))
  7.  
  8. list_1 = [*range(10), 10, 11, 13, 15]
  9. list_2 = [*range(10), 12, 14]
  10. print(combine(list_1, list_2))
Success #stdin #stdout 0.03s 9812KB
stdin
Standard input is empty
stdout
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]