May-21-2021, 11:25 AM
The following code will recursively display the contents of a dictionary nested or not.
def display_dict(dictname, level=0): indent = " " * (4 * level) for key, value in dictname.items(): if isinstance(value, dict): print(f'\n{indent}{key}') level += 1 display_dict(value, level) else: print(f'{indent}{key}: {value}') if level > 0: level -= 1level is used internally to control the node level.