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
An internet layer is a quantity of data that is transmitted on a netowrk without concern for whether it is accurate or whether i
satela [25.4K]

Answer:

False

Explanation:

The statement being made here is a False statement. An internet layer is not necessarily a quantity of data but instead, it is a group of various different codes, programs, and protocols that allow from the data to travel safely from one endpoint to the other. This is what allows one user from one side of the world to send information to someone else who can receive it from the other side of the world through the internet.

7 0
3 years ago
Two ways of calculating average returns are ______ and ______. Multiple select question. the arithmetic average the progressive
joja [24]

Answer:

"Geometric Average Return Example. Jennifer has invested $5,000 into a money market that earns 10% in year one, 6% in year two, and 2% in year three. If you were to calculate this using the arithmetic mean return, you would add the rates together and divide them by three, giving you an average of 6%."

Explanation:

6 0
2 years ago
Team members support one another when they view differences as being? A) annoyances they can live with B) signs of poor training
cricket20 [7]
C (dont mind this sentence it is so that i can reach 20 characteristics)




























                                          
6 0
3 years ago
Read 2 more answers
Postsecondary certificated programs are commonly referred to as:
denpristay [2]
I believe it is commonly referred as a college/vocational school/ or a university.
3 0
3 years ago
In what four ways do we commonly respond?
Gnoma [55]

Answer:

A

Explanation:

4 0
3 years ago
Other questions:
  • What is the disk bandwidth? the total number of bytes transferred total time between the first request for service and the compl
    13·1 answer
  • Compute the sum of all integers that are multiples of 9, from 1 to 250. Enter your result of your computation in the text box be
    9·2 answers
  • "A file named numbers.txt contains an unknown number of lines, each consisting of a single integer. Write some code that compute
    9·1 answer
  • Express 0.0005 x 10-4 farads as picofarads
    5·2 answers
  • Why might you receive a tax refund from the irs
    6·1 answer
  • ____ is scientifically seeking and discovering facts.
    9·1 answer
  • Why is it important to ensure that your software is up to date?
    13·1 answer
  • The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
    10·1 answer
  • How can using Prezi software for a presentation allow the presenter to better respond to audience needs?
    10·1 answer
  • Anybody got a quisten
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!