r/pythonhelp • u/[deleted] • Feb 14 '18
Python assignment help
"Write a function that takes a tree and a function and maps each element of the tree to the passed in function"
Given the functions: label which returns tree[0]
branches which returns tree[1:]
is_tree checks if is tree
is _leaf checks if is leaf
and tree constructor
tree(label,branches=[]):
for branch in branches:
assert(is_tree(branch))
return [label] + list(branches)
0
Upvotes