I have information about a (simplified example) hierarchical taxonomy,
A - AA - AAA
A - AA - AAB
A - AB
B
I have data for it as a list of dicts in the following format:
[
{"name": "A",
"id": 10,
"path": ["A"]},
{"name": "AA",
"id": 7,
"path": ["A", "AA"]}
...
]
(the id is random)
I am trying to show it in a dash treeview widget based on AntD. It requires me to convert it to the following format:
[{"title": "A", "key": 10, "children":
[{"title": "AA", "key": 11, "children":
[{...}] ,
{"title": "AB", "key": 12},
...]},
{"title": "B", "key": 18}]
In other words, it's a recursive list of dicts, where there is a key called "children", which is another list of dicts taking on the same format.
I know I need to write a recursive function, but it's proving very tricky for me.