Method "subtrees_sorted_by" is not implemented in an efficient way.
The following function is far more efficient (in terms of computation time) for computing a dictionary that the native method subtrees_sorted_by
. I suggest try to look at the aforementioned method and investigate whether a more efficient implementation can be done.
def subtrees_sorted_by_height(t):
nodes_sorted ={}
for u in t.list_of_subtrees():
height = u.get_property('height')
if height not in nodes_sorted.keys():
nodes_sorted[height]=[u]
else:
nodes_sorted[height].append(u)
return nodes_sorted