energia.utils.dictionary#
dictionary utils
Functions
|
How many periods make this period |
Hashable signature of a dict for grouping. |
|
|
Recursively convert defaultdict to dict. |
|
Makes a flat dictionary from a nested dictionary. |
|
Finds the depth of a dictionary. |
|
Same as a is b. |
Convert nested dict to level-wise compact structure, merging repeated keys at all levels. |
|
|
Recursively merge two tree-like dicts (values always dicts). |
|
Makes a list of tuples of keys in a nested dictionary. |
Classes
|
defaultdict(default_factory=None, /, [...]) --> dict with default factory |
Exceptions
Raised when two periods are not linked in the period tree. |
- get_depth(d: dict) int[source]#
Finds the depth of a dictionary.
- Parameters:
d (dict) – The dictionary to measure.
- Returns:
Depth of the dictionary.
- Return type:
int
- flatten(d: dict, key: tuple = ()) dict[source]#
Makes a flat dictionary from a nested dictionary.
- Parameters:
d (dict) – The dictionary to flatten.
key (tuple, optional) – Current key path. Defaults to
().
- Returns:
Flattened dictionary with tuple keys.
- Return type:
dict
- tupler(d: dict, path: tuple = ()) list[tuple[str]][source]#
Makes a list of tuples of keys in a nested dictionary.
- Parameters:
d (dict) – The dictionary to traverse.
path (tuple, optional) – Current path. Defaults to
().
- Returns:
List of tuples of keys representing the paths to each value.
- Return type:
list[tuple[str]]
- merge_trees(d1: dict, d2: dict) dict[source]#
Recursively merge two tree-like dicts (values always dicts).
- Parameters:
d1 (dict) – First dictionary.
d2 (dict) – Second dictionary.
- Returns:
Merged dictionary.
- Return type:
dict
- dictify(d: defaultdict | dict) dict[source]#
Recursively convert defaultdict to dict.
- Parameters:
d (defaultdict | dict) – The dictionary to convert.