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]
2 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]2 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 a win-win situation?
Ilia_Sergeevich [38]
A. Each party benefits in some way
6 0
3 years ago
Plzz help.... <br><br>i will mark u as brainliest if u answer correct
shtirl [24]

Answer:

import java.util.Scanner;

class Main {

 public static void main(String[] args) {

   Scanner scan = new Scanner(System.in);

   while(true) {

     System.out.print("Enter an integer (0 to exit): ");

     int num = scan.nextInt();

     if (num == 0) break;

     if (num%3 == 0 && num%5 == 0) {

       System.out.printf("%d is divisable by both 3 and 5.\n", num);

     }

     else if (num%3 == 0 && num%5 != 0) {

       System.out.printf("%d is divisable by 3 but not by 5.\n", num);

     }

     else if (num%3 != 0 && num%5 == 0) {

       System.out.printf("%d is divisable by 5 but not by 3.\n", num);

     } else {

       System.out.printf("%d is not divisable by 3 or 5.\n", num);

     }

   }

   scan.close();

 }

}

3 0
3 years ago
What is the difference between Remote Assistance and Remote Desktop?
9966 [12]
Remote Desktop allows remote connections and controls how long an invitation to connect remains open; Remote Assistance lets you choose whether to allow connections, not allow connections, and add or remove certain
7 0
2 years ago
I wanna start answering questions for people, but I don't quite know how. Can you help me?​
Vsevolod [243]

Answering questions on brainly?

6 0
3 years ago
How to convert binary to decimal <br> Please it’s so hard and what is digital and analogue
geniusboy [140]

Answer:

How to convert binary to decimal ?

It consists of digits from 0 to 9. Binary to decimal conversion can be done in the simplest way by adding the products of each binary digit with its weight (which is of the form - binary digit × 2 raised to a power of the position of the digit) starting from the right-most digit which has a weight of 20.

what is digital and analogue?

In analog technology, a wave is recorded or used in its original form. So, for example, in an analog tape recorder, a signal is taken straight from the microphone and laid onto tape.In digital technology, the analog wave is sampled at some interval, and then turned into numbers that are stored in the digital device.

8 0
2 years ago
Other questions:
  • would specify that only selected members of the payroll and human resources department would have the right to change sensitive
    11·1 answer
  • What does zooming do? A. Changes your view of the Frame Editor to be closer or farther away B. Changes your view of the Event Ed
    12·1 answer
  • Please help me complete this task for ICT! Its about Hardware and Software
    12·1 answer
  • Which describes the first step a crawler-based search engine uses to find information?
    10·2 answers
  • Why was Apple the best company of 2019??
    15·2 answers
  • Why when I move stuff in Roblox Studio like an object or a Character. It tilts the opposite direction I'm moving it to with the
    6·2 answers
  • AWT
    7·1 answer
  • What best describes the ability to increase the access to server resources and provide fail-safe services by linking two or more
    13·1 answer
  • Can someone please help me answer the extension activity and the exit ticket. I’ll award you. Thanks❤️.
    12·1 answer
  • How many operations can a computer perform every second?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!