code: def _append_nested(
      collection: Any,
      data: Union[
          np.ndarray, List[Any], Tuple[Any, ...], Dict[str, Any]
      ],
  ) -> Any:
      """Appends data to the more nested dimension of collection.
  
      Args:
        collection: collection constructed by appending elements like data to the
          most nested dimension. It is of type Union[np.ndarray, List[Any],
          Tuple[Any, ...], Dict[str, Any]] but using this causes type errors because
          it considers that we are trying to append to a dict or a tuple.
        data: data logged by DM Env Logger that can be a scalar, array, dict or
          tuple.
  
      Returns:
        Collection with data appended to the nested dimension.
      """
      if isinstance(data, dict):
          for k in collection:
              _append_nested(collection[k], data[k])
          return collection
      elif isinstance(data, tuple):
          return tuple(
              _append_nested(collection[index], value)
              for index, value in enumerate(data)
          )
      else:
          collection.append(data)
          return collection
  
file_path: datasets/tensorflow_datasets/rlds/envlogger_reader.py
imports: from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Union
  import numpy
  from tensorflow_datasets.core.utils import tree_utils
label_desc: Use image node_id 9 for calling a global function with example usage: _append_nested(collection, data) and returns: collection, tuple, collection