Question: Use Python country) that follows these criteria: i. There needs to be at least 3 levels of hierarchyesting. ii. Each level in the hierarchy needs

Use Python
Use Python country) that follows these criteria: i. There needs to be

country) that follows these criteria: i. There needs to be at least 3 levels of hierarchyesting. ii. Each level in the hierarchy needs to have at least 3 locations (i.e. 1 country with 3 regions, each of those regions with 3 cities, etc.). So you'll have a structure consisting of 1 level 1 dictionary, 3 level 2 dictionaries, 9 level 3 dictionaries, and so on. iii. Each dietionary representing a level needs to have the following key/value pairs: 1. name: The name of the location (i.e. city name for a city location). 2. locationType: The type of location (i.e. city, state, province, etc.) 3. population: The number of people at the location. 4. children: A list to hold the nested locations. This should be an empty list for the lowest level dictionaries. b. Create a function at the top of your code that has the following features: i. This function will perform a deep copy of a location, so name it accordingly. ii. It must have an appropriate docstring. iii. This function will accept a parameter for the location dictionary to copy. iv. Create a new variable named clonedLocation and set it to an empty dictionary. v. Set the clonedLocation's locationType, name, and population keys to the parameter's corresponding value (i.e. copy the values from the original to the clone). vi. Loop through the parameter's children and for each iteration of the loop: 1. Recursively call this same function, but pass in the current child as the argument. Store the return value of the recursive function call to a variable named clonedChild. 2. Check if the clonedLocation is missing its children key and set it to an empty list if so. 3. Append the clonedChild to the clonedLocation's children list. vii. Return the clonedLocation variable. c. In your main code section, below where you've defined your example locations list (i.e. 5a), call your function from 5b, pass in your top level location, and store the return value in a new variable. d. Print the original and cloned locations

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!