[Python] How can I transform a nested list to tree with branches?