code: def _split_user_def_targets(
      datasets,
      targets: Optional[Union[Sequence[T], Sequence[Sequence[T]]]],
      single_element_checker: Callable[[Any], bool],
  ) -> List[Optional[Sequence[T]]]:
      """
      Given a datasets list and the user-defined list of targets,
      returns the targets list of each dataset.
  
      This internal utility is mainly used to manage the different ways
      in which the user can define the targets:
      - A single list of length equal to the sum of the lengths of all datasets
      - A list containing, for each dataset, a list, defining the targets
          of each exemplar of a that dataset
  
      :param datasets: The list of datasets.
      :param targets: The user-defined targets. Can be None, in which
          case a list of None will be returned.
      :returns: A list containing as many elements as the input `datasets`.
          Each element is either a list of targets or None. If None
          (because `targets` is None), this means that the targets
          should be retrieved by traversing each dataset.
      """
      t_labels = []
      idx_start = 0
      for dd_idx, dd in enumerate(datasets):
          end_idx = idx_start + len(dd)
          dataset_t_label: Optional[Sequence[T]]
          if targets is None:
              # No targets set
              dataset_t_label = None
          elif single_element_checker(targets[0]):
              # Single targets sequence
              # (to be split across concatenated datasets)
              dataset_t_label = targets[idx_start:end_idx]  # type: ignore
          elif len(targets[dd_idx]) == len(dd):  # type: ignore
              # One sequence per dataset
              dataset_t_label = targets[dd_idx]  # type: ignore
          else:
              raise ValueError(
                  "The targets parameter has an invalid format."
              )
          t_labels.append(dataset_t_label)
  
          idx_start = end_idx
      return t_labels
  
imports: from collections import OrderedDict, defaultdict, deque
  from typing import TYPE_CHECKING, Any, Callable, Generic, Iterator, List, Iterable, Mapping, Optional, Sequence, TypeVar, Union, Dict, SupportsInt
  import warnings
  import torch
  from torch import Tensor
  from torch.utils.data import Subset, ConcatDataset
  from .data import AvalancheDataset
  from .data_attribute import DataAttribute
  from .dataset_definitions import ISupportedClassificationDataset
  from .dataset_utils import SubSequence, find_list_from_index
  from .flat_data import ConstantSequence
  from .transform_groups import TransformGroupDef, TransformGroups, XTransform, YTransform
label_desc: Use image node_id 16 for calling a global function with example usage: _split_user_def_targets(datasets, targets, single_element_checker) and returns: t_labels