Python Recursive Program to sum Nested List Elements
defrecursive_list_sum(data_list):
total =0for element in data_list:iftype(element)==type([]):
total = total + recursive_list_sum(element)else:
total = total + element
return total
print( recursive_list_sum([1,2,[3,4],[5,6]]))
No comments:
Post a Comment