subject

Lists can hold integers, strings, and even other lists, for example [ ["test"], [ ], [1. ["me"] ] ) is a list with three elements: a list ["test"), an empty list [ ], and a list [1. ["me"] ]. When objects like lists or dictionaries contain objects of the same type as themselves, we say the inner objects are nested in the outer objects For an object in a nested list, we will call the number of enclosing outer lists the depth of that object.
For example, in the list [ ["test"], [ ], [1, ["me"] } ], the list ["test") is at a depth of 1, the string "test" is at a depth of 2 and the string "me" is at a depth of 3.
Write a recursive function to calculate the maximum depth of any object in a given list.
Name the function maximum_nesting_depth(x), where x is a list, and return an integer representing the maximum depth of any object inx.
You can assume the test cases will not be the empty list.
Examples:
maximum_nesting_depth([ ("test"], [], [1, ["me"] ] ]) = 3
maximum_nesting_depth(["test"]) = 1
maximum_nesting_depth([ 1, ["me"] ] = 2
Note that empty lists will not contribute to the nesting depth; we are computing the maximum nesting depth of any object maximum_nesting_depth [ "test", [ ] ] is 1 because "test" is at depth 1 maximum_nesting_depth([ "test", [[ ]]]is 2 because[ ] is at depth 2 and empty Hint 1: You can use the following recursive definition: Base Case: If x is a list containing no lists, the maximum nesting depth is 1. Recursive Case: If x is a list containing a list with maximum nesting depth of n, then x has a maximum nesting depth of at least n+1. Hint 2: For an object e, the expression "isinstanceſe, list)" will be True if and only if e is a list.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:00
Program description: a c# app is to be created to produce morse code. the morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). in sound-oriented systems, the dot represents a short sound and the dash represents a long sound. separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. in a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. the international version of the morse code is stored in the data file morse.txt.
Answers: 3
question
Computers and Technology, 22.06.2019 11:00
The editing of digital photos us about the same level of difficulty as editing an analog photo
Answers: 2
question
Computers and Technology, 22.06.2019 18:00
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
question
Computers and Technology, 23.06.2019 03:10
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
You know the right answer?
Lists can hold integers, strings, and even other lists, for example [ ["test"], [ ], [1. ["me"] ] )...
Questions
question
Mathematics, 28.09.2021 16:00
question
Biology, 28.09.2021 16:10
question
Mathematics, 28.09.2021 16:10
question
Mathematics, 28.09.2021 16:10