Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions