0
したがって、バイナリ文字列ツリーをとり、すべての葉の長さの合計を返すtotal_len()
という再帰関数を定義する必要があります。Python 3.4.3:バイナリ文字列ツリー内の文字列の長さの合計
total_len((("one", ("two","three")) , ("four","five")))
は
total_len(("left","right"))
9を返す必要があり、かつ
total_len("One-leaf")
が、私は本当に開始するために理解していない、と私は私が持っていることは完全に間違っていることを知っているが、私はこれまで持っていることはこれで8を返す必要があり、19を返す必要があります
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