Given 4 trees in a dictionary form:
tree0 = {}
tree1 = {'L': {}, 'R': {}, 'V': 3}
tree2 = {'L': {'L': {}, 'R': {}, 'V': 2}, 'R': {'L': {}, 'R': {'L': {}, 'R': {}, 'V': 6}, 'V': 1}, 'V': 5}
tree = {'L': {'L': {}, 'R': {'L': {'L': {}, 'R': {'L': {'L': {}, 'R': {'L': {}, 'R': {}, 'V': 9}, 'V': 4}, 'R': {}, 'V': 13}, 'V': 2}, 'R': {}, 'V': 8}, 'V': 3}, 'R': {'L': {}, 'R': {'L': {}, 'R': {}, 'V': 6}, 'V': 1}, 'V': 5}
How can I make a function depth_t(t)
, that takes as argument one of the trees above, that determines the depth of the tree recursively, without using a class?
I have been struggling with this. The only thing I got was:
if len(t)==0: return 0
Can somebody give me some tips?
The depths of all trees above are:
tree0 depth 0
tree1 depth 1
tree2 depth 3
tree depth 7
tree['L'] depth 6
Thanks in advance!