input: Write a function to implement binary search in Python which efficiently finds the index of a target value in a sorted list. If the target value is found, the function should return its index; otherwise, it returns -1.
  
  def binary_search(nums, val):
      low = 0
      high = len(nums) - 1
      
      while low <= high:
          mid = (low + high) // 2
          if nums[mid] == val:
              return mid
          elif nums[mid] > val:
              high = mid - 1
          else:
              low = mid + 1
      return -1
  
  assert binary_search([3, 4, 5, 6, 7, 8, 9], 8) == 5
  assert binary_search([3, 4, 5, 6, 7, 8, 9], 3) == 0
  assert binary_search([1, 2, 3, 4, 5], 6) == -1
  assert binary_search([], 10) == -1
  assert binary_search([7, 10, 11, 12, 15, 20], 15) == 4
output: def binary_search(nums, val):
      low = 0
      high = len(nums) - 1
      
      while low <= high:
          mid = (low + high) // 2
          if nums[mid] == val:
              return mid
          elif nums[mid] > val:
              high = mid - 1
          else:
              low = mid + 1
      return -1