def disk_space(tree: Tree, position: Tree.Position): """ :param tree: tree :param position: position :return: the total disk space for subtree of tree rooted at position """ total = 0 if tree.is_leaf(position) and isinstance(position.element(), File): total = position.element().size for c in tree.children(position): total += disk_space(tree, c) return total
def parenthesis(tree: Tree, position: Tree.Position): """ Print parenthesized representation of tree rooted at the position :param tree: tree :param position: position :return: """ print(position.element(), end="") if not tree.is_leaf(position): first_time = Tree for c in tree.children(position): if first_time: print("(", end="") else: print(",", end=" ") first_time = False parenthesis(tree, c) print(")", end="")