I'm trying to make a function that returns the sum of all integers in a tree list in the format:
element 1 is an integer
element 2 is another treelist or None
element 3 is another treelist or None
ex: [1,[1,None,None],None]
so basically i want my function to add up all the integers in that list and return 2.
This is what i made so far..
def sum_nested(t):
sum = 0
for i in t:
if type(i) == type(None):
sum += 0
if type(i) == list:
return sum_nested(i)
else:
sum = sum + i
return sum
However, I get the error:
builtins.TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
cant seem to figure out what to do when i hit that None type..any suggestions?