input: Write a function to perform a binary search to find the first occurrence of a target value in a sorted list.
  assert binary_search([1, 3, 3, 4, 5, 6, 8], 3) == 1
  assert binary_search([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5) == 4
  assert binary_search([2, 4, 4, 4, 6, 8, 10], 4) == 1
  assert binary_search([1, 1, 1, 1, 1, 2], 1) == 0
  assert binary_search([1, 3, 5, 7, 9], 6) == -1
output: def binary_search(nums, target):
      left, right = 0, len(nums) - 1
      result = -1
      while left <= right:
          mid = left + (right - left) // 2
          if nums[mid] == target:
              result = mid
              right = mid - 1
          elif nums[mid] < target:
              left = mid + 1
          else:
              right = mid - 1
      return result