In [103]: def traverse_tree(tree, indent = 0):
...: edges = []
...:
...: for subtree in tree:
...: print(' '*indent, 'edges:', edges)
...: print(' '*indent, 'tree', subtree, '\n')
...: if isinstance(subtree, nltk.tree.Tree):
...: if subtree.label() == 'Pred' or subtree.label() == 'Var':
...: edges.append((subtree.leaves()[0], traverse_tree(subtree, indent + 1)))
...: else:
...: edges.append(traverse_tree(subtree, indent + 1))