I have list of file paths and need them to be organized in a tree structure like the following.
{
"label": "VP Accounting",
"children": [
{
"label": "iWay",
"children": [
{
"label": "Universidad de Especialidades del Espíritu Santo"
},
{
"label": "Marmara University"
},
{
"label": "Baghdad College of Pharmacy"
}
]
},
{
"label": "KDB",
"children": [
{
"label": "Latvian University of Agriculture"
},
{
"label": "Dublin Institute of Technology"
}
]
},
what I did so far is the following
output = {}
current = {}
for path in paths :
current = output
for segment in path.split("/") :
if segment != '':
if segment not in current:
current[segment] = {}
current = current[segment]
The output is a tree like structure but I can not add the keys ["label", "children"]