a. Create a nested hierarchy of dictionaries that represent locations on a map (address, city, state/region,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a. →Create a nested hierarchy of dictionaries that represent locations on a map (address, city, state/region, country) that follows these criteria:< i. → There needs to be at least 3 levels of hierarchy/nesting.< 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 dictionary 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.→location Type: 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 cloned Location and set it to an empty dictionary.< v. → Set the cloned Location's location Type, 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 cloned Child.< 2. Check if the cloned Location is missing its children key and set it to an empty list if so.< 3.→Append the clonedChild to the cloned Location's children list.< v vii. Return the cloned Location variable.< a. →Create a nested hierarchy of dictionaries that represent locations on a map (address, city, state/region, country) that follows these criteria:< i. → There needs to be at least 3 levels of hierarchy/nesting.< 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 dictionary 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.→location Type: 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 cloned Location and set it to an empty dictionary.< v. → Set the cloned Location's location Type, 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 cloned Child.< 2. Check if the cloned Location is missing its children key and set it to an empty list if so.< 3.→Append the clonedChild to the cloned Location's children list.< v vii. Return the cloned Location variable.<
Expert Answer:
Answer rating: 100% (QA)
Heres a Python code example that creates a nested hierarchy of dictionaries representing locations on a map and includes a function for deep copying a ... View the full answer
Related Book For
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young
Posted Date:
Students also viewed these programming questions
-
How does data management within an information system impact the effectiveness and success of laboratory projects?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Pricing in imperfect markets (continuation of 22-28). Refer to Problem 22-28. 1.Suppose the manager of Division A has the option of (a) cutting the external price to $195, with the certainty that...
-
A uniform electric field of magnitude 3.8 105 N/C points in the positive x direction. Find the change in electric potential energy of a 7.5-(C charge as it moves from the origin to the points (a)...
-
Given a copy of a completed Primary Spelling Assessment, students will analyze the data to discover the following information: 1. Determine student's spelling developmental level; 2. Write one goal...
-
Write the following numbers in scientific notation form: 1. 428.9 2. -0.00000981 3. 8
-
Clapton Company manufactures custom guitars in a wide variety of styles. The following incomplete ledger accounts refer to transactions that are summarized for May: In addition, the following...
-
Basic Bookkeeping - Level 7 Steps XY Consumer Products 687 Nottingham Park Drive London, ON N6A 4V8 Invoice No. 679 Customer No. FM4568 Sold To: Fred Milsom Ship To: same 321 Laurentian Cres. Sarnia,...
-
8. A financial analyst is forecasting the expected return for the stock of Himalayan Motors. The analyst estimates the following probability distribution of returns: Probability Return 20% -5% 40 10...
-
Determine changes you think any company should make based on the variance analysis. What will the changes accomplish?
-
1. In the Serratia marcescens cell, where are the genes located? the gene is located in the Chrasomes cytoplasm 2. In diploid organisms, like humans or mice or pine trees, where are the two copies of...
-
Assuming that apples are a "normal" good, identify how the following events would change the equilibrium price and quantity: A growing economy increases overall wages Extraordinarily good growing...
-
A pre-mixed concrete firm has to supply concrete with shipping costs as shown in the following table; the demand and supply are also shown. Plants A B C Demand (m3) Pr1 8 LE/m3 9 14 450 Projects Pr2...
-
Explain the difference between multiuser and multitasking. Give an example of an OS that is multiuser and one that is not.? The X25 demodulator machine has been upgraded to modern computer...
-
Analyze the impact of the global economic crisis on the American economy. you will have an opportunity to discuss and apply your insights on the principles of macroeconomic and microeconomic theories...
-
Based on your findings, would you want to conduct business with this organization? (1 mark) Why or why not (2 marks) organization: e2open
-
What is the shape of the exponential distribution?
-
Relevant costs and revenues: replacement decision Joyce Printers, Inc., is considering replacing its current printing machines with newer, faster, and more efficient printing technology. The...
-
Operating budgets: materials purchasing plan Masefield Dairy is preparing a third-quarter budget (July, August, and September) for its ice cream products. It produces five brands of ice cream, and...
-
Product mix and overtime decisions Excel Corporation manufactures three products at its plant. The plant capacity is limited to 120,000 machine hours per year on a single-shift basis. Direct material...
-
2. Joya is the head of the personal insurance division of a large insurance company. Six months before, she was almost promoted to vice-president, but she lost out to Bill, a colleague from another...
-
4. Mark is an executive for a multinational office equipment company that would like to enter the potentially vast Chinese market. The official tariffs on office equipment imported into China are so...
-
3. Executives were considering the possibility of moving their company to a different state. They wanted to determine if employees would be willing to relocate, but they did not want the employees to...
Study smarter with the SolutionInn App