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
Discuss the most enormous cases of a data breach in the twenty-first century
barxatty [35]

Answer:

Gary McKinnon

Hak Nasa technecly a goverment servers

Explanation:

7 0
3 years ago
Question very important cause after my school is over at 5 'oclock I will be playing rocket league if anyone wants to play just
jarptica [38.1K]

Answer:

So can u tell me wut is ur question...It is not understandable

6 0
3 years ago
The scope of a variable declared inside of a function is:
Feliz [49]

Answer:

The correct answer for the given question is option(a) i.e Local - within that function .

Explanation:

The variable which is declared inside any function are called as local variable The scope and lifetime of local variable is inside that block or function only.

They cannot access outside the function.

Following are the example of local variable

#include <stdio.h> // header file

void fun(); // function prototype

int main()// main function

{

fun(); //calling function

print("%d",t); // it gives error because t is local variable cannot access in main function

return 0;

}

void fun()

{

int t=9;// local variable

printf("t is local variable which value is:");

printf("%d",t);

}

As we seen that t cannot access outside the function .So correct answer is option(a)

7 0
3 years ago
Ecommerce sites sell this to generate income
prisoha [69]
They sell products through ads.
7 0
3 years ago
How will you maintain electrical tools and equipment?
PSYCHO15rus [73]
Electronic tools should not rub against each other when stored. Keep all the tools in the dry area and protect them from moisture, dust, and direct sunlight. To prevent injuries, keep the sharpen tool in a tool holder.
4 0
3 years ago
Read 2 more answers
Other questions:
  • When using the strcat function, you must be careful not to overwrite the bounds of an array?
    5·1 answer
  • The __________ of a desktop computer is the case that houses the computerâs critical parts, such as the processing and storage d
    5·1 answer
  • When using IPsec, how can you ensure that each computer uses its own private key pair?
    12·1 answer
  • Why is redundancy of data undersirable?
    7·2 answers
  • Which type of RAM is used exclusively in laptops?<br> a) SODIMM<br> b) DDR3<br> c) DDR<br> d) DDR4
    15·1 answer
  • LEAF library in py can be expressed in what form?
    6·1 answer
  • Draw a flowchart diagram for a program that display a person's name x times​
    5·1 answer
  • Dgvdsgf cvdzgb fgvsdxchygfdrzvdszfgvsdzxd
    9·1 answer
  • 1. Write a programme to print the Fees Receipt of English High School Required Inputs Name of the Student Monthly Tuition Fees M
    10·1 answer
  • Complete each sentence. To add a graphic to a Word document, start by clicking the tab. Next, click . Then, navigate to the grap
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!