human
Give me a Python program to find the index of the first occurrence of a given number in a sorted array given the following:
Write a function to find the index of the first occurrence of a given number in a sorted array. Here is a solution in Python:
assistant
#Here is Python program to find the index of the first occurrence of a given number in a sorted array.
 def find_first_occurrence(A, x):
    (left, right) = (0, len(A) - 1)
    result = -1
    while left <= right:
        mid = (left + right) // 2
        if x == A[mid]:
            result = mid
            right = mid - 1
        elif x < A[mid]:
            right = mid - 1
        else:
            left = mid + 1
    return result