A nested list is a list whose elements are lists:
l be the list and
l3 be the sub lists:
l1 = [1,2,3] l2 = [4,5,6] l3 = [7,8,9] l = [[1,2,3],[4,5,6],[7,8,9]]
l = [[1,2,8], [3,5,5], [4,6,6]] count=0 for i in l: for j in i: if(j%2==0): count=count+1 print(count)
A nested list,
l, is taken with sub-lists.
Count variable is used to count the number of even numbers in the list and is initialized to zero.
for loop is used to access the elements in the list.
i is used to access sub-lists in the list, and variable
j is used to access elements in sub-list
Th even condition is checked with
j and, if it is satisfied, the
count value is incremented by one.
View all Courses