code: def restructure_results(
      result_path: Union[Path, str],
      target_path: Union[Path, str] = Path("structured_results"),
  ) -> None:
      """Restructures results from a given path.
  
      Transforms the structure from the original
      <dataset_name>/<method_name>/results.pickle to <dataset_name>/<method_name>.pickle.
  
      Parameters
      ----------
      result_path : Path
          Path to the results.
      target_path : Path, optional
          Path to save the restructured results, by default Path("structured_results").
      """
      if isinstance(result_path, str):
          result_path = Path(result_path)
      if isinstance(target_path, str):
          target_path = Path(target_path)
      result_paths = glob.glob(
          str(result_path / "*" / "*" / "results.pickle")
      )
      for result_file in result_paths:
          dataset = result_file.split("/")[-3]
          method = result_file.split("/")[-2]
          if not (target_path / dataset).exists():
              (target_path / dataset).mkdir()
          with open(result_file, "rb") as f:
              results = pickle.load(f)
          with open(
              target_path / dataset / f"{method}.pickle", "wb"
          ) as f:
              pickle.dump(results, f)
  
imports: import glob
  import pickle
  from pathlib import Path
  from typing import Union
  from aequitas.fairflow.evaluation import Result
label_desc: Use image node_id 1 for calling a global function with example usage: restructure_results(result_path, target_path) without return types