input: Write a function to optimize the given Python code using best practices. The given function performs a linear search in an array to find the index of a specified element x. If the element is found, it returns the index; otherwise, it returns -1.
  assert linear_search([1, 2, 3, 4], 3)==2
  assert linear_search([1, 2, 3, 4], 5)==-1
  assert linear_search([], 3)==-1
  assert linear_search([1, 2, 3, 4], 1)==0
output: def linear_search(arr, x):
      for i, value in enumerate(arr):
          if value == x:
              return i
      return -1