Monday, June 29, 2020

Python Recursive Program to sum Nested List Elements

def recursive_list_sum(data_list): total = 0 for element in data_list: if type(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