Question: Using Python!! Write a recursive function count(lst,target) that finds the number of occurrences of target in a nested list, where each item in the list
Using Python!!
Write a recursive function count(lst,target) that finds the number of occurrences of target in a nested list, where each item in the list is either a number, or, another list (which itself could be listed). The list transversal will be similar to the function total written in class. Example:
>>> count( [1,2,3,[4,5,5],[[5,2,1],4,5],[3]], 1 )
2
>>> count( [1,2,3,[4,5,5],[[5,2,1],4,5],[3]], 5 )
4
>>> count( [1,2,3,[4,5,5],[[5,2,1],4,5],[3]], 0 )
0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
