I thought about writing code to do a "depth-first traversal" of this tree, but then I remembered PyCogent. It has functions that manipulate trees. All we have to do is to convert our data to a form that it can recognize:
It's easiest to load the data from a file, so first we write it: