input: Write a function to implement the insertion sort algorithm for sorting a list of n distinct integers. The function should return the sorted list.
  
  def insertion_sort(arr):
      for i in range(1, len(arr)):
          key = arr[i]
          j = i-1
          while j >= 0 and key < arr[j]:
              arr[j + 1] = arr[j]
              j -= 1
          arr[j + 1] = key
      return arr
  
  assert insertion_sort([5, 3, 1, 4, 2])==[1, 2, 3, 4, 5]
  assert insertion_sort([4, 8, 1, 3, 2, 6, 5, 7])==[1, 2, 3, 4, 5, 6, 7, 8]
  assert insertion_sort([1])==[1]
  assert insertion_sort([])==[]
output: def insertion_sort(arr):
      for i in range(1, len(arr)):
          key = arr[i]
          j = i-1
          while j >= 0 and key < arr[j]:
              arr[j + 1] = arr[j]
              j -= 1
          arr[j + 1] = key
      return arr