def flatten_(structure):
    """Combine all leaves of a nested structure into a tuple.

  The nested structure can consist of any combination of tuples, lists, and
  dicts. Dictionary keys will be discarded but values will ordered by the
  sorting of the keys.

  Args:
    structure: Nested structure.

  Returns:
    Flat tuple.
  """
    if isinstance(structure, dict):
        result = ()
        for key in sorted(list(structure.keys())):
            result += flatten_(structure[key])
        return result
    if isinstance(structure, (tuple, list)):
        result = ()
        for element in structure:
            result += flatten_(element)
        return result
    return (structure,)