def is_int( e) :
return type ( e) == int
def deep_lst_sum( lst) :
total = 0
def helper( lst) :
if lst == [ ] :
return 0
elif is_int( lst[ 0 ] ) == True :
total += lst[ 0 ]
return helper( lst[ 1 :] )
else :
return helper( lst[ 0 ] )
helper( lst)
return total
deep_lst_sum( [ 6 , 2 , [ 8 , 4 , 5 ] , [ 9 , [ 5 ] ] ] )
ZGVmIGlzX2ludChlKToKICByZXR1cm4gdHlwZShlKSA9PSBpbnQKCmRlZiBkZWVwX2xzdF9zdW0obHN0KToKICAgIHRvdGFsID0gMAogICAgZGVmIGhlbHBlcihsc3QpOgogICAgICAgIGlmIGxzdCA9PSBbXToKICAgICAgICAgICAgcmV0dXJuIDAKICAgICAgICBlbGlmIGlzX2ludChsc3RbMF0pID09IFRydWU6CiAgICAgICAgICAgIHRvdGFsICs9IGxzdFswXQogICAgICAgICAgICByZXR1cm4gaGVscGVyKGxzdFsxOl0pCiAgICAgICAgZWxzZToKICAgICAgICAgICAgcmV0dXJuIGhlbHBlcihsc3RbMF0pCiAgICBoZWxwZXIobHN0KQogICAgcmV0dXJuIHRvdGFsCgpkZWVwX2xzdF9zdW0oWzYsIDIsIFs4LCA0LCA1XSwgWzksIFs1XV1dKSAgICA=
stdout
stderr
Traceback (most recent call last):
File "./prog.py", line 17, in <module>
File "./prog.py", line 14, in deep_lst_sum
File "./prog.py", line 10, in helper
UnboundLocalError: local variable 'total' referenced before assignment