input: Write a function to optimize the provided Python code according to best practices. The input code performs a linear search on an array to find a specific element `x` and returns its index if found, otherwise returns -1.
  
  def linear_search(arr, x):
      for index, item in enumerate(arr):
          if item == x:
              return index
      return -1
  
  assert linear_search([1, 2, 3, 4, 5], 3) == 2
  assert linear_search([1, 2, 3, 4, 5], 6) == -1
  assert linear_search([], 3) == -1
  assert linear_search(['a', 'b', 'c'], 'b') == 1
  assert linear_search(['a', 'b', 'c'], 'd') == -1
output: def linear_search(arr, x):
      try:
          return arr.index(x)
      except ValueError:
          return -1