1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ne4ueva [31]
3 years ago
14

The function below takes two arguments: a dictionary of strings (keys) to integers (values) a_dict and a list of strings key_lis

t. All of the strings in the list are keys to the dictionary. Complete the function such that it looks up each of the keys in the list and returns a list of their associated values. The order of the values in the list is based on the order of the keys in key_list. For example, with the dictionary {"puffin": 5, "corgi": 2, "three": 3} and the list ["three", "corgi"], your function should return [3, 2]. student.py
Computers and Technology
1 answer:
vitfil [10]3 years ago
8 0

Answer:

  1. def getData(a_dict, key_list):
  2.    result = []
  3.    for key in key_list:
  4.        result.append(a_dict[key])
  5.    
  6.    return result  
  7. result = getData( {"puffin": 5, "corgi": 2, "three": 3} , ["three", "corgi"])
  8. print(result)

Explanation:

Let's define a function <em>getData() </em>with two parameters,<em> a_dict </em>and <em>key_list</em> as required by the question (Line 1).

Since the function is to return a list of associated values of dictionaries, a new list,<em> result</em>,  is declared and initialized with empty values (Line 2).

Next, use for-loop to traverse through every string in the input <em>key_list </em>(Line 4) and use the traversed key to address the value in the<em> a_dict </em>and add it to the <em>result</em> list (Line 5)

At last, return the <em>result </em>list as output (Line 7)

We can test the function using the test case from the question and we shall see the output as follows:

[3, 2]

You might be interested in
What is an active cooling solution for a PC?
mina [271]
Reduce the speed of the CPU
6 0
3 years ago
Read 2 more answers
Which term describes the distinct number of colors a graphic contains? (1 point)?
laila [671]
Your answer would be "Hue".
4 0
3 years ago
Which type of chart is preferable when you are dealing with a timeframe?
ANTONII [103]

Answer:

Pie chart

Explanation:

Just get to know

7 0
2 years ago
Ideally, how long or how many sentences should your video game pitch be?
Olin [163]
Good shot hdhhdbsb suhsbsbs bbsbsbsbdbbdbdbdbdbbd
6 0
3 years ago
Select the correct answer.
aliina [53]

Answer:

B

Explanation:

engineers design and carry out test cases and evaluate exit criteria (by following the scope set in the planning phase). They create bug reports describing detected defects and report to the stakeholders on the test findings and the completion status. Testing may be repeated to check for errors.

7 0
3 years ago
Other questions:
  • What are the primary functions of motor oil? a. Reduce friction and prevent wear b. Keep engine surfaces clean c. Remove heat to
    11·1 answer
  • Which best describes the differences between a resume and a CV?
    13·2 answers
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • A barcode is a Select one: a. coded instruction needed to control computer hardware. b. confidential computer code required by H
    7·1 answer
  • What is microsoft certification?
    8·1 answer
  • Question 2 of 3
    7·2 answers
  • What is used to accurately position objects on the slide using a single horizontal and vertical line that intersects in the cent
    12·2 answers
  • This isn't an academic question, but can anyone help me change the face on my apple watch to a picture from my camera roll? I've
    15·1 answer
  • Quick question if anyone knows? How do you give brainlist? Please tell me if you know! ( Here if a chiaki gif for your too lol )
    5·1 answer
  • Look at the code in the example below, and then answer the question.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!