input: Write a function to optimize the given Python code using best practices. The function should implement a linear search, where it searches for an element `x` in an array `arr`. If the element is found, it should return its index, otherwise it should return -1. The function should use enumeration to improve the readability and efficiency of the code.
  
  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([], 1)==-1
  assert linear_search([1, 2, 3, 4, 5], 5)==4
  assert linear_search([1, 1, 1, 1], 1)==0
output: def linear_search(arr, x):
      for index, item in enumerate(arr):
          if item == x:
              return index
      return -1