def merge_sorted_lists(a, b): res = [] len_a, len_b = len(a), len(b) i = j = 0 while i < len_a and j < len_b: if a[i] < b[j]: res.append(a[i]) i += 1 else: res.append(b[j]) j += 1 res += a[i:] + b[j:] return res