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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!