python code now works through making the tree