1def normalize(tree, row=0, col=0):
2 try:
3 node = tree[row][col]
4 left = normalize(tree, row+1, col*2)
5 right = normalize(tree, row+1, col*2+1)
6 return [node, left, right] if left or right else [node]
7 except:
8 return None # child index does not exist