I have a dictionary made of array of values which I would like to get all the values related to condition. This is a dummy sample of the structure:
d = {'condition': 'Approval expected.', 'sub_conditions': [
{'condition': 'Approved Activities: {reading} {crafting}', 'sub_conditions': [
{'condition': 'Field Areas: # of areas, dimensions - {start_date} {end_date} {email}', 'sub_conditions': [
{'condition': 'Room Areas: # of rooms, dimensions - {start_date} {end_date} {email}',
'sub_conditions': []}]}]}]}
subconditions is an array of dictionaries made of conditions which I would like to get. Currently, I am visiting each condition value as follows:
for layer_one in d['sub_conditions']:
print(layer_one['condition'])
for layer_two in layer_one['sub_conditions']:
print(layer_two['condition'])
for layer_three in layer_two['sub_conditions']:
print(layer_three['condition'])
#it can have more layers
This is giving me the output I need:
Approved Activities: {reading} {crafting}
Field Areas: # of areas, dimensions - {start_date} {end_date} {email}
Room Areas: # of rooms, dimensions - {start_date} {end_date} {email}
I was wondering better ways to iterate over this type of dictionary. What would be the best approach in this case?