Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with a Python recursion problem: The functions written must not use global variables. In some cases certain built-in functions are restricted in your

Need help with a Python recursion problem:

The functions written must not use global variables. In some cases certain built-in functions are restricted in your solutions so carefully read each question.

image text in transcribed

Write recursive function depthCount0 that takes an arbitrarily nested list as a parameter and returns the maximum depth to which the list has nested sublists. For example, a list with no sublists would have depth 0. A list with a sublist that contains no sublists itself would have depth 1. Every time a sublist of the list has a sublist itself, the depth increases by 1. There are several examples provided below for your reference. You are not allowed to use any list methods in your function other than indexing (e.g. lst for some integer slicing (lst[ij] for some integers i and j), or len0. Remember that you can test whether an item is a list by writing: if type(item) list. In writing the function you should not use any loops. You may assume that the initial value given to the function is a list, and your function does not have to behave in any reasonable way when given something other than a list as a parameter. The following shows the behavior of the function on some sample parameters. Please remember that these examples are just that. Your function must work correctly on all valid parameters, and you may not make any assumptions about the number of nested sublists or the depth of the nesting in the list provided as a parameter to the function. Python 3.4.1 Shell File Edit Shell Debug Options Windows Help depthCount (CJ) depthCount 1, 2, 31) depthCount (CE1], C2 3]]) depthCount (C [[1] J C2 3]] depth Count (CC1] [C2] 31]) depthCount (CC [11] depthCount (C1, CCCC2], 3]] Ln: 39 Col: 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+ How would you advise those problems be resolved?

Answered: 1 week ago