GHpython: Append and addup each branch in datatree create a new tree

Hi, all, I have a datatree, say A, and output_tree being the new tree that append each A’s branch’value to the previous branch.

this is what I did so far… which I have no clue what I am doing tdh…realy new to python.

import rhinoscriptsyntax as rs
import ghpythonlib.treehelpers as th

branchcount = x.BranchCount
branches = x.Branches
path = x.Paths
output_tree = [] 

#for every new tree branchlist append the points in the previous branchlist.
for pt in range(branchcount):
    new_path = path(pt+1)
    output_tree += list(branches[pt])

Tree = th.list_to_tree(output_tree , True)

Wish for some help, and really thankful if anyone could explain their code a little.