input: Write a function to optimize the given python code using best practices. Provide the optimized version of the function along with the input and expected output.
  
  def linear_search(arr, x):
      for index, item in enumerate(arr):
          if item == x:
              return index
      return -1
  
  #assert
  assert linear_search([1, 2, 3, 4, 5], 3) == 2
  assert linear_search([1, 2, 3, 4, 5], 6) == -1
  assert linear_search([], 5) == -1
  assert linear_search(["apple", "banana", "cherry"], "banana") == 1
  assert linear_search(["apple", "banana", "cherry"], "grape") == -1
output: def linear_search(arr, x):
      return next((index for index, item in enumerate(arr) if item == x), -1)