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, 21.06.2019 22:00
What do the principles of notice, choice, onward transfer, and access closely apply to? a. privacyb. identificationc. retentiond. classification
Answers: 1
question
Computers and Technology, 22.06.2019 13:50
The instruction ishl (shift left integer) exists in jvm but not in ijvm. it uses the top two values on the stack, replacing the two with a single value, the result. the sec- ond-from-top word of the stack is the operand to be shifted. its content is shifted left by a value between 0 and 31, inclusive, depending on the value of the 5 least signifi- cant bits of the top word on the stack (the other 27 bits of the top word are ignored). zeros are shifted in from the right for as many bits as the shift count. the opcode for ishl is 120 (0x78).a. what is the arithmetic operation equivalent to shifting left with a count of 2? b. extend the microcode to include this instruction as a part of ijv.
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Alex’s family members live in different parts of the world. they would like to discuss the wedding plans of one of their distant relatives. however, alex wants all the family members to talk to each other simultaneously so that they can make decisions quickly. which mode of internet communication should they use? a. blog b. email c. wiki d. message board e. instant messaging
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
Which is the correct sequence of steps to set up a document in landscape orientation? a. select page setup from the file menu. then click the margins tab and select landscape. b. select page setup from the edit menu. then click the margins tab and select landscape. c. select page setup from the insert menu. then click the margins tab and select landscape. d. select page setup from the format menu. then click the margins tab and select landscape
Answers: 1
You know the right answer?
Lists can hold integers, strings, and even other lists, for example [ ["test"], [ ], [1. ["me"] ] )...
Questions
question
Biology, 23.12.2020 18:00
question
Mathematics, 23.12.2020 18:00
Questions on the website: 13722367