def recursive_count(target, nested_num_list):
# This code finds all occurrences of "target" in "nested_num_list"
# Rewrite this code without a while/for loop that achieves
# the same results. Basically using only recursive calls and if's.
count = 0
i = 0
while i < len(nested_num_list):
if nested_num_list[i] == target:
count += 1
if type(nested_num_list[i]) == type([]):
count += recursive_count(target, nested_num_list[i])
i += 1
return count
This was a bonus question (read the hashtags) that came up in my computation class. I've tried default parameters, tinkering with i and count numerous ways but I cant get it. How would you lovely people go about it?