Dec-27-2020, 02:54 AM
Nested dictionaries are allowed and useful
eachsub dictionary does require a key, so have made d1, d2 and d3
I added display dict so that you can display contents
eachsub dictionary does require a key, so have made d1, d2 and d3
I added display dict so that you can display contents
newdict = { 'd1': {'Dia': 'qua', 'Promo': 'João', 'Loja': 6697}, 'd2': {'Dia': 'qui', 'Promo': 'João', 'Loja': 5599}, 'd3': {'Dia': 'sex', 'Promo': 'João', 'Loja': 7437} } 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 -= 1 if __name__ == '__main__': display_dict(newdict)output when run:
Output:d1
Dia: qua
Promo: João
Loja: 6697
d2
Dia: qui
Promo: João
Loja: 5599
d3
Dia: sex
Promo: João
Loja: 7437