I am currently practicing python and I am having an issue with binary tree. I think I am fairly good in python but I am having a hard time with binary trees.
The problem is:

The first line of the function definition is given so I need to use it as is, however not sure how to calculate sum of branches.
def solution(arr):
root = arr[0]
for i in arr.index(i):
left = sum(arr[i]-arr[0])
right = sum(arr[i+1]-arr[0])
if left > right:
return "Left"
elif left < right:
return "Right"
else:
return ""
The error I get is
Traceback (most recent call last):
File "/usercode/file.py", line 36, in <module>
test()
File "/usercode/file.py", line 34, in test
json.dumps(solution(*input), separators=(',', ':')))
File "/usercode/file.py", line 5, in solution
for i in arr.index(i):
UnboundLocalError: local variable 'i' referenced before assignment
ibefore you use it inarr.index(i). What are you trying to do in this line?