input: Write a function to implement a merge sort algorithm that takes two sorted lists A and B and merges them into a single sorted list. The algorithm should compare the first elements of both lists, append the smaller element to the result list, and move the pointer to the next element in the list from which the smaller element was taken. If one list is exhausted, it should append the remaining elements of the other list to the result. Continue this process until all elements from both lists are in the result list.
  
  def merge_sort(A, B):
      result = [] 
      i, j = 0, 0
  
      # Compare elements and add the smaller one to the result
      while i < len(A) and j < len(B):
          if A[i] < B[j]:
              result.append(A[i])
              i += 1
          else:
              result.append(B[j])
              j += 1
  
      # Add remaining elements
      result += A[i:]
      result += B[j:]
  
      return result
  
  assert merge_sort([3, 6, 8, 10, 11], [2, 5, 7, 12]) == [2, 3, 5, 6, 7, 8, 10, 11, 12]
  assert merge_sort([1, 3, 5], [2, 4, 6]) == [1, 2, 3, 4, 5, 6]
  assert merge_sort([], [2, 4, 6]) == [2, 4, 6]
  assert merge_sort([1, 3, 5], []) == [1, 3, 5]
  assert merge_sort([], []) == []
output: def merge_sort(A, B):
      result = [] 
      i, j = 0, 0
  
      while i < len(A) and j < len(B):
          if A[i] < B[j]:
              result.append(A[i])
              i += 1
          else:
              result.append(B[j])
              j += 1
  
      result += A[i:]
      result += B[j:]
  
      return result