Question: Iterate through a dictionary using the built-in enumerate() function. example_dict = {1:'a', 2:'b', 3:'c', 4:''} for i, (k, v) in enumerate (example_dict.items()): print(i, k, v)

 Iterate through a dictionary using the built-in enumerate() function. example_dict =

Iterate through a dictionary using the built-in enumerate() function. example_dict = {1:'a', 2:'b', 3:'c', 4:''} for i, (k, v) in enumerate (example_dict.items()): print(i, k, v) The first column of output is the index of enumeration and the last two colums are its keys and values. Question: Suppose that you are setting up engineering requirements and targets for a project as in question 5 of assignment 1. You have decided that the engineering requirements and targets are: 1. Speaker size, 40mm 2. Volume, 80dB 3. Weight, 300g Program to do the following: . Step 1: Create a dictionary variable original_design_parameters={} to include the above engineering requirements and targets as keys and values. For keys, use speaker_size_mm, volume_db, weight_g . For values, use integer numbers. Step 2: Create a copy of original_design_parameters with name new_design_parameters Suppose that there is additional user defined requirements and targets stored in user_defined={} dictionary. user_defined={'impedance_ohm':100, 'bass_response_Hz' :15, 'weight_g': 250) Step 3: Iterate over the user_defined dictionary. If the design requirement is aleady exists, update its value in new_design_parameter if necessary. If the design requirement is new, update the dictionary new_design_parameter with new key-value pair. Step 4: Finally, convert the dictionary new_design_parameter into a list of tuples tuples_new_design_parameter. Input: { 'aa': 10, 'bb': 11, cc': 13 } Output: [ ('aa', 10), ('bb', 11), ('cc', 13) ] In [28]: original_design_parameters = { 'speaker_size_mm' :40, 'volume_db':80, 'weight_g':300} user_defined={'impedance_ohm':100, 'bass_response_Hz':15, 'weight_g':250) Create a copy of design_parameter new_design_parameters = original_design_parameters.copy ( ) code for Step 3 for i, (k,v) in enumerate(user_defined. items()): if # code for Step 4 #print(new_design_parameters) #print(tuples_new_design_parameter)

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!