combine¶
- combine(data: dict, levels: tuple[int, int], delim: str = '-') dict[source][source]¶
Combine any levels of a nested dict into the lower level
Takes the input nested dict and rearranges the top and bottom sub-dictionary.
- Parameters:
- Returns:
The combined dict
- Return type:
Examples
>>> data = {'a': {'b': {'c': 1}}} >>> combine(data, (0, 2)) {'b': {'a-c': 1}} >>> data = {'a': {'b': {'c': 1}}, 'd': {'b': {'c': 2, 'e': 3}}} >>> combine(data, (0, 2)) {'b': {'a-c': 1, 'd-c': 2, 'd-e': 3}}