I have an object in Python that’s comprised of nested dictionaries, such as
my_dict = {
"status": "ok",
"data': {"column1":0,
"column2":1}
}
How would I traverse this object in order to map it onto the following dict?
my_dict = [
{"field":"status",
"value": "ok"},
{"field": "data',
"value": [{"field": "column1", "value":0},
{"field":"column2", "value":1}
]
}
]
I’m aware that I may achieve this mapping for a 0-level dictionary by doing
my_list = []
for k,v in dict.items():
my_list.append({"field": k, "value": v})
and I’m inclined to say that this problem requires doing some kind of graph walking algorithm such as DFS or BFS, but I’m not really acquainted to theses techniques beside intuition. Any advice?