I know questions regarding accessing key, value in a nested dictionary have been asked before but I'm having some trouble with the following piece of my code:
For accessing the keys and values of a nested dictionary as follows:
example_dict = {'key_outer_01': {'key_inner_01': 'value_inner_01'},
'key_outer_02': {'key_inner_02': 'value_inner_02'}}
I have the following piece of code:
def get_key_value_of_nested_dict(nested_dict):
for key, value in nested_dict.items():
outer_key = None
inner_key = None
inner_value = None
if isinstance(value, dict):
outer_key = key
get_key_value_of_nested_dict(value)
else:
inner_key = key
inner_value = value
return outer_key, inner_key, inner_value
The output that I'm getting is:
key_outer_01 None None
What am I doing wrong here?