Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Created October 17, 2016 17:07
Show Gist options
  • Select an option

  • Save fogonthedowns/7dd65e72c318dc37f6089fb1b0174dbd to your computer and use it in GitHub Desktop.

Select an option

Save fogonthedowns/7dd65e72c318dc37f6089fb1b0174dbd to your computer and use it in GitHub Desktop.
proper tree parse scipy ClusterNode object
def parse(tree, p):
path = p[:]
path.append(str(tree.get_id()))
if tree.is_leaf():
print('.'.join(path))
else:
#Here I assume get_left() returns some falsey value for no left child
left = tree.get_left()
if left:
parse(left, path)
right = tree.get_right()
if right:
parse(right, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment