0
所以我需要定义一个名为total_len()
的递归函数,它需要一个二进制字符串树并返回所有树叶长度的总和。所以total_len((("one", ("two","three")) , ("four","five")))
应该返回19,total_len(("left","right"))
应该返回9,并且total_len("One-leaf")
应该返回8.我真的不知道从哪里开始,我知道我拥有的是完全错误的,但是我到目前为止是这样的:Python 3.4.3 .:二进制字符串树中所有字符串长度的总和
def total_len(BST):
"""Takes a binary string tree and returns the sum of all the lengths of
of all the leaves.
BST->int"""
if isinstance(BST,tuple):
return total_len(len(BST[0][0])+total_len(len(BST[1][0])))
else:
return BST