input: def optimize_code(code: str) -> str:
      """ Optimize the given Python code using best practices.
      >>> optimize_code(\"\"\"def linear_search(arr, x):
      ...     for i in range(len(arr)):
      ...         if arr[i] == x:
      ...             return i
      ...     return -1\"\"\")
      'def linear_search(arr, x):\\n    for index, item in enumerate(arr):\\n        if item == x:\\n            return index\\n    return -1\\n'
      """
output:     import ast
      import astor
  
      class CodeOptimizer(ast.NodeTransformer):
          def visit_For(self, node):
              if isinstance(node.target, ast.Name) and isinstance(node.iter, ast.Call) and isinstance(node.iter.func, ast.Name) and node.iter.func.id == 'range':
                  if len(node.iter.args) == 1 and isinstance(node.iter.args[0], ast.Call) and isinstance(node.iter.args[0].func, ast.Name) and node.iter.args[0].func.id == 'len':
                      arr = node.iter.args[0].args[0].id
                      for stmt in node.body:
                          if isinstance(stmt, ast.If) and isinstance(stmt.test, ast.Compare) and isinstance(stmt.test.left, ast.Subscript) and stmt.test.left.value.id == arr:
                              new_node = ast.For(
                                  target=ast.Tuple(elts=[ast.Name(id='index', ctx=ast.Store()), ast.Name(id='item', ctx=ast.Store())], ctx=ast.Store()),
                                  iter=ast.Call(func=ast.Name(id='enumerate', ctx=ast.Load()), args=[ast.Name(id=arr, ctx=ast.Load())], keywords=[]),
                                  body=[ast.If(test=ast.Compare(left=ast.Name(id='item', ctx=ast.Load()), ops=[ast.Eq()], comparators=[stmt.test.comparators[0]]), body=stmt.body, orelse=[])],
                                  orelse=[],
                                  type_comment=None
                              )
                              return new_node
              return node
  
      tree = ast.parse(code)
      optimizer = CodeOptimizer()
      optimized_tree = optimizer.visit(tree)
      return astor.to_source(optimized_tree)