Last active
August 19, 2021 07:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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