I don't know that i would use range on the list.
All though there are other ways but, maybe like this
All though there are other ways but, maybe like this
mylist = [5,[5, 3, 3],5,5,5] # List of numbers def sum_nested_list(mylist): # set the finction variable total = 0 # Loop through the list checking for other list for num in mylist: if type(num) == list: # If a list is found, get the sum and add to total total += sum(num) else: total += num # else add the num to total return total # return the total print(sum_nested_list(mylist))
Output:31
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags