code: def create_cross_validation_datalist(
      datalist: list[dict],
      nfolds: int,
      train_folds: Sequence[int] | int,
      val_folds: Sequence[int] | int,
      train_key: str = "training",
      val_key: str = "validation",
      filename: Path | str | None = None,
      shuffle: bool = True,
      seed: int = 0,
      check_missing: bool = False,
      keys: KeysCollection | None = None,
      root_dir: str | None = None,
      allow_missing_keys: bool = False,
      raise_error: bool = True,
  ):
      """
      Utility to create new Decathlon style datalist based on cross validation partition.
  
      Args:
          datalist: loaded list of dictionaries for all the items to partition.
          nfolds: number of the kfold split.
          train_folds: indices of folds for training part.
          val_folds: indices of folds for validation part.
          train_key: the key of train part in the new datalist, defaults to "training".
          val_key: the key of validation part in the new datalist, defaults to "validation".
          filename: if not None and ends with ".json", save the new datalist into JSON file.
          shuffle: whether to shuffle the datalist before partition, defaults to `True`.
          seed: if `shuffle` is True, set the random seed, defaults to `0`.
          check_missing: whether to check all the files specified by `keys` are existing.
          keys: if not None and check_missing_files is True, the expected keys to check in the datalist.
          root_dir: if not None, provides the root dir for the relative file paths in `datalist`.
          allow_missing_keys: if check_missing_files is `True`, whether allow missing keys in the datalist items.
              if False, raise exception if missing. default to False.
          raise_error: when found missing files, if `True`, raise exception and stop, if `False`, print warning.
  
      """
      if check_missing and keys is not None:
          files = check_missing_files(
              datalist, keys, root_dir, allow_missing_keys
          )
          if files:
              msg = f"some files of the datalist are missing: {files}"
              if raise_error:
                  raise ValueError(msg)
              warnings.warn(msg)
  
      data = partition_dataset(
          data=datalist,
          num_partitions=nfolds,
          shuffle=shuffle,
          seed=seed,
      )
      train_list = select_cross_validation_folds(
          partitions=data, folds=train_folds
      )
      val_list = select_cross_validation_folds(
          partitions=data, folds=val_folds
      )
      ret = {train_key: train_list, val_key: val_list}
      if isinstance(filename, (str, Path)):
          with open(filename, "w") as f:
              json.dump(ret, f, indent=4)
  
      return ret
  
file_path: MONAI/monai/data/decathlon_datalist.py
imports: from __future__ import annotations
  import json
  import os
  import warnings
  from collections.abc import Sequence
  from pathlib import Path
  from typing import overload
  from monai.config import KeysCollection, PathLike
  from monai.data.utils import partition_dataset, select_cross_validation_folds
  from monai.utils import ensure_tuple
label_desc: Use image node_id 8 for calling a global function with example usage: create_cross_validation_datalist(datalist, nfolds, train_folds, val_folds, train_key, val_key, filename, shuffle, seed, check_missing, keys, root_dir, allow_missing_keys, raise_error) and returns: ret