Functions for working with arbitrarily nested sequences of elements.
This module can perform operations on nested structures. A nested structure is a
Python sequence, tuple (including
namedtuple), or dict that can contain
further sequences, tuples, and dicts.
The utilities here assume (and do not check) that the nested structures form a 'tree', i.e., no references in the structure of the input of these functions should be recursive.
((3, 4), 5, (6, 7, (9, 10), 8)),
(np.array([3, 4]), tf.constant([3, 4])))
assert_same_structure(...): Asserts that two structures are nested in the same way.
assert_shallow_structure(...): Asserts that
shallow_tree is a shallow structure of
flatten(...): Returns a flat list from a given nested structure.
flatten_dict_items(...): Returns a dictionary with flattened keys and values.
input_tree up to
flatten_with_joined_string_paths(...): Returns a list of (string path, data element) tuples.
get_traverse_shallow_structure(...): Generates a shallow structure from a
is_sequence(...): Returns a true if its input is a collections.Sequence (except strings).
func to each entry in
structure and returns a new structure.
map_structure_up_to(...): Applies a function or op to a number of partially flattened inputs.
pack_sequence_as(...): Returns a given flattened sequence packed into a given structure.
yield_flat_paths(...): Yields paths for some nested structure.