filmov
tv
Write a Python Program to Sum All The Items in a Nested List [Recursion Used]

Показать описание
Hello Programmers, Welcome to my channel.
In this video you will learn about how to Write a Python Program to Sum All The Items in a Nested List [Recursion Used]
Python Scripts
======================
Python Functions Solved
==========================
Python Programs Solved
============================
Code
=============================
def find_sum(data):
local_sum = 0
for item in data:
if isinstance(item, list):
local_sum += find_sum(item)
elif isinstance(item, int):
local_sum += item
return local_sum
my_list = [1, 2, 3, [4, 5, 6, [7, 8]], 9]
total = find_sum(my_list)
print("Sum of all Items in Nested List is : ", total)
Keywords
=============================
#python #python3 #python_assignment #pythonprogramming #pythontutorial #pythonprojects #pythoncourse #pythonbaba #pythonforbeginners #pythonautomation #pythonbasic #pythonbeginners
In this video you will learn about how to Write a Python Program to Sum All The Items in a Nested List [Recursion Used]
Python Scripts
======================
Python Functions Solved
==========================
Python Programs Solved
============================
Code
=============================
def find_sum(data):
local_sum = 0
for item in data:
if isinstance(item, list):
local_sum += find_sum(item)
elif isinstance(item, int):
local_sum += item
return local_sum
my_list = [1, 2, 3, [4, 5, 6, [7, 8]], 9]
total = find_sum(my_list)
print("Sum of all Items in Nested List is : ", total)
Keywords
=============================
#python #python3 #python_assignment #pythonprogramming #pythontutorial #pythonprojects #pythoncourse #pythonbaba #pythonforbeginners #pythonautomation #pythonbasic #pythonbeginners