The levels needs to look like this:
- Task: xxxxxx1
- Subtask: xxxxxx2
- Sub subtask: xxxxxx3
- Sub subtask: xxxxxx4
- Subtask: xxxxxx2
- Task: xxxxxx5
- Subtask: xxxxxx6
I am struggling to arrange all tasks and subtasks in a new dict at the correct level like the example above with the example data. Please keep in mind, the example shows 3 levels but there can be more than 3 levels depending on the client creating the ticket.
I know this is not correct way to do this, and it's not finished:
data = {'tasks':
[
{'id': 'xxxxxx1','parent': None},
{'id': 'xxxxxx2','parent': 'xxxxxx1'},
{'id': 'xxxxxx3','parent': 'xxxxxx2'},
{'id': 'xxxxxx4','parent': 'xxxxxx2'},
{'id': 'xxxxxx5','parent': None},
{'id': 'xxxxxx6','parent': 'xxxxxx5'}
]
}
taskData = {}
subTaskData = {}
for task in data['tasks']:
###task IDs with no parent
if not task['parent']:
taskData.setdefault(task['id'],[])
else:
subTaskData.setdefault(task['id'],[""])
print(taskData)
print(subTaskData)
I would appreciate it if someone can help me with this using Python? I believe I can use something called recursive??