I try to sum a list of nested elements
e.g, numbers=[1,3,5,6,[7,8]] should produce sum=30
numbers=[1,3,5,6,[7,8]]
sum=30
I wrote the following code :
This code also works.
def add_all(t): total = 0 for i in t: if type(i) == list: # check whether i is list or not total = total + add_all(i) else: total += i return total