input: Write a function to optimize the provided Python code by using best practices. If the code is already optimized, return the same code. Use the `linear_search` function as an example and apply any necessary improvements.
  assert linear_search([3, 4, 5, 1, 2], 5)==2
  assert linear_search([3, 5, 10, 1, 2], 10)==2
  assert linear_search([4, 3, 1, 2], 1)==2
  assert linear_search([3, 5, 4, 1, 2], 4)==2
  assert linear_search([], 1)==-1
  assert linear_search([1, 2, 3], 4)==-1
output: def linear_search(arr, target):
      for i, value in enumerate(arr):
          if value == target:
              return i
      return -1