Write a function count_div5(nested_list) that takes in a list of lists of integers, and returns a list of integers representing how many integers in each sublist of the original were divisible by 5.
Examples:
>>> count_div5([[5, 3, 25, 4], [46, 7], [5, 10, 15]])
[2, 0, 3]
>>> count_div5([])
[]
>>> count_div5([[-20, 10, 2, 4, 5], [], [5], [8, 25, 10], [6]])
[3, 0, 1, 2, 0]
def count_div5(nested_list):
list1=[]
for i in range(len(nested_list)):
count=0
for j in range(len(nested_list[i])):
if(int(nested_list[i][j])%5==0):
count=count+1
list1.append(count)
return list1
print(count_div5([[5, 3, 25, 4], [46, 7], [5, 10,
15]]))
Get Answers For Free
Most questions answered within 1 hours.