Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary {"puffin": 5, "corgi": 2, "three": 3} and the list ["three", "corgi"], your function should return {"corgi": 2, "three": 3}. Since dictionaries are unordered, you can add the keys to the new dictionary in any order.

Respuesta :

Limosa

Answer:

The following are the program in the Python Programming Language.

#define function

def get_subset(dic,lst):

   #declare dictionary type array

   res = {}

   #set the for loop

   for a in lst:

       #set the if conditional statement

       if a in dic:

           #assign the value of 'dic' in the 'res'

           res[a] = dic[a]

   #return the variable 'res'

   return res

Explanation:

The following are description of the program.

  • In the above program, define the function 'get_subset()' and pass two arguments in its parameter 'dic' and 'lst'.
  • Declare dictionary type variable 'res' then, set the for loop.
  • Then, set the if conditional statement that checks the elements of the variable 'a' in the variable 'dic' and assigns the value of 'dic' in the variable 'res'.
  • Finally, return the variable 'res'.

Dictionary, list, strings and integers are all data types of the Python programming language

The get_subset function in Python where comments are used to explain each line is as follows:

#This defines the function

def get_subset(mydict,myList):

   #This declares the output dictionary

   outputDict = {}

   #This iterates through the loop

   for item in myList:

       #This checks if the current item exists in the dictionary

       if item in mydict:

           #If yes, the item is appended to the output dictionary

           outputDict[item] = mydict[item]

   #This returns the output dictionary

   return outputDict

Read more about functions at:

https://brainly.com/question/14186324