code: def flatten_with_path(
      structure: Tree[T],
  ) -> Iterator[
      Tuple[Tuple[Union[str, int], ...], T]
  ]:  # pytype: disable=invalid-annotation
      """Convert a TreeDict into a flat list of paths and their values.
  
      ```py
      flatten_with_path({'a': {'b': v}}) == [(('a', 'b'), v)]
      ```
  
      Args:
        structure: Nested input structure
  
      Yields:
        The `(path, value)` tuple. With path being the tuple of `dict` keys and
          `list` indexes
      """
      if isinstance(structure, dict):
          key_struct_generator = sorted(structure.items())
      elif isinstance(structure, (list, tuple)):
          key_struct_generator = enumerate(structure)
      else:
          key_struct_generator = None  # End of recursion
  
      if key_struct_generator is not None:
          for key, sub_structure in key_struct_generator:
              # Recurse into sub-structures
              for sub_path, sub_value in flatten_with_path(
                  sub_structure
              ):
                  yield (key,) + sub_path, sub_value
      else:
          yield (), structure
  
imports: import base64
  import contextlib
  import functools
  import io
  import itertools
  import logging
  import os
  import random
  import re
  import shutil
  import string
  import sys
  import textwrap
  import threading
  import typing
  from typing import Any, Callable, Dict, Iterator, List, NoReturn, Optional, Tuple, Type, TypeVar, Union
  import uuid
  from absl import logging
  from etils import epath
  from six.moves import urllib
  from tensorflow_datasets.core import constants
  from tensorflow_datasets.core.utils import type_utils
label_desc: Use image node_id 10 for calling a global function with example usage: flatten_with_path(structure) without return types