input: Write a function to optimize the given python code using best practices. The given code performs a linear search in an array and returns the index of the first occurrence of the target element if found, otherwise returns -1.
  
  ### Original Code:
  def linear_search(arr, x):
      for i in range(len(arr)):
          if arr[i] == x:
              return i
      return -1
  
  ### Optimized Code:
  def linear_search(arr, x):
      for index, item in enumerate(arr):
          if item == x:
              return index
      return -1
  
  assert linear_search([3, 4, 5, 1, 2], 5) == 2
  assert linear_search([3, 4, 5, 1, 2], 6) == -1
  assert linear_search([], 1) == -1
output: def linear_search(arr, x):
      for index, item in enumerate(arr):
          if item == x:
              return index
      return -1