Skip to content

Commit

Permalink
use list
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Apr 29, 2024
1 parent 75752ea commit 997f2ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compas/datastructures/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,22 +454,22 @@ def hierarchy(self, max_depth=None):
"""

hierarchy = {"string": ""}
hierarchy = []

def traverse(node, hierarchy, prefix="", last=True, depth=0):

if max_depth is not None and depth > max_depth:
return

connector = "└── " if last else "├── "
hierarchy["string"] += "{}{}{}\n".format(prefix, connector, node)
hierarchy.append("{}{}{}".format(prefix, connector, node))
prefix += " " if last else "│ "
for i, child in enumerate(node.children):
traverse(child, hierarchy, prefix, i == len(node.children) - 1, depth + 1)

traverse(self.root, hierarchy)

return hierarchy["string"]
return "\n".join(hierarchy)

def to_graph(self, key_mapper=None):
"""Convert the tree to a graph.
Expand Down

0 comments on commit 997f2ce

Please sign in to comment.