this code problem
def height(t): """return depth of deepest node in tree.""" if isinstance(t, list): t = t[1:] if t != empty: return 1 + max([height(x) x in t]) return 0 but doesn't return value expect. can figure out? thanks. , tree method is:
def tree(entry, subtrees=[]): return lambda dispatch: entry if dispatch == 'entry' else list(subtrees) def entry(tree): return tree('entry') def subtrees(tree): return tree('subtrees')
the param t of height function should tree, expect list if isinstance(t, list), obviously, isn't list, return 0.
because height function wrong. height function didn't call entry or subtrees function.
should subtrees of tree, if empty, return 1. if not empty, return 1 + max of height of subtrees of t.
i don't paste code, please check yourself.
Comments
Post a Comment