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
Nancy would like to configure an automatic response for all emails received while she is out of the office tomorrow, during busi
marishachu [46]

Answer:

I believe the answer is the second one

5 0
3 years ago
Read 2 more answers
In cell h15 enter a vlookup function to determine the 2018 percentage of total attendance for the city listed in cell h14. Use t
Amanda [17]

Answer:

=vlookup(h14, a5:h11,8,false)

Explanation:

Here, h15 is the cell in which we need the output and the value to be matched in rows to find the exact row is h14, and the range is expressed as a5:h11. Now to find the column number, we need to figure out the first and the concerned column. So, the concerned column is in which the total attendance is being listed and it is h(h14), and the first column is a. So, the column number is a=1 h=8, =8. And since we need the exact match, the value of the fourth argument is false. And thus, we have the above formula. Remember. vlookup formula is:

=vlookup(cell where the result is to be placed, range, column number in the same row as h14, exact match or approximate match). For exact match it's false, and for the approximate match, it's true.

8 0
3 years ago
Write a recursive function is_pow2(n) that returns True if the positive integer n is an integer power of 2, and False otherwise.
bezimeni [28]

Answer:

In Python:

def is_power(n):

   if n > 2:

       n = n/2

       return is_power(n)

   elif n == 2:

       return True

   else:

       return False

Explanation:

This defines the function

def is_power(n):

If n is greater than 0

   if n > 2:

Divide n by 2

       n = n/2

Call the function

       return is_power(n)

If n equals 2

   elif n == 2:

Return True

       return True

If n is less than 2

   else:

Then, return false

       return False

8 0
2 years ago
What kind of software consists of the programs that control or maintain the operations of a computer and its devices?
patriot [66]
Instructional coding hope this helps
6 0
2 years ago
Which of the following is a command shell with a built-in scripting language?1. The Server Manager’s Roles and Features wizard2.
IgorLugansk [536]
Your kinda right but wrong
4 0
3 years ago
Read 2 more answers
Other questions:
  • Define a function begins_with_line that consumes a string and returns a boolean indicating whether the string begins with a dash
    15·1 answer
  • What do we call a subset of new media in which groups and their fans can interact directly?
    14·1 answer
  • Discuss three ways you could (or currently do) use the Excel software in your personal or professional life. Provide examples an
    12·1 answer
  • How to get this on your screen in 2k20 on Xbox
    14·2 answers
  • AddAll - Adds all the doubles in the string with each other. Note every double is separated by a semi-colon. AddAll("1.245;2.9")
    6·1 answer
  • Which is a benefit of getting information from a government website?
    15·2 answers
  • What is the function of a breadcrumb trail in a website ?
    10·2 answers
  • What is the difference between private inheritance and composition?
    11·1 answer
  • What would be an ideal scenario for using edge computing solutions?
    10·1 answer
  • Which of the following statements about ip addresses is true?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!