我的部分问题是编写一个确定树高度的函数。
这是我目前的功能,
def tree_height(node):
parent, children = node
max_height = 0
for child in children:
height = tree_height(child)
if height > max_height:
max_height = height
return max_height
但它只返回 0。
* 注意:输入参数应该只有一个,即节点 *
为了,
tree = ("supercalifragilisticexpialidocious",(("a",(("b",(("candy",()),)),("onomatopoeia",()),)),("d",(("egg",(("f",()),)),)),))
输出应该是,
3