In python, I have a list of nested lists that represents a binary tree:
L = [0, [[1, [2, 3]], [4, [5, 6]]]]
So the tree can be seen as follows:
0
/ \
1 4
/\ /\
2 3 5 6
I now want to implement a function that takes as input a level of the tree and returns all the nodes of that level:
GetNodes(0) = 0
GetNodes(1) = [1,4]
GetNodes(2) = [2,3,5,6]
Is there an easy way to do this, avoiding a brutal search on all the nested lists of L
?
Is there the possibility of a more standard management of binary trees in python, maybe converting my list of lists in something else?