Skip to content

Instantly share code, notes, and snippets.

@damascenodiego
Last active August 19, 2021 07:52
Show Gist options
  • Save damascenodiego/22974e75d732f17b2436140145af9bf1 to your computer and use it in GitHub Desktop.
Save damascenodiego/22974e75d732f17b2436140145af9bf1 to your computer and use it in GitHub Desktop.
Python code to parse a (sub)tree starting from a node nid to the horizontal format. None elements
# Python code to parse a (sub)tree starting from a node nid to the horizontal format.
# Returns a python list with node IDs. None elements indicates backtracking
def tree_to_hformat(tree, nid = 0, list_hformat=None):
if list_hformat is None:
list_hformat = []
list_hformat.append(nid)
for child in tree.successors(nid):
tree_to_hformat(tree, child, list_hformat)
list_hformat.append(None)
return(list_hformat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment