The function below, find_largest_value_key, takes a single argument: a dictionary data_dict. The dictionary can have any data type as a key, but all of the dictionaries values are of type integer. All of the values are positive integers. Complete the function below to return the key which corresponds to the largest value in the dictionary. For example, given the dictionary {"sample": 15, 5: 25}, the function should return 5

Respuesta :

Answer:

The completed code for the function in Python is given in the bold font.

Explanation:

def find_largest_value_key(data_dict):

   largeValue = None

   result = None

   for k in data_dict.keys():

       if(largeValue==None or largeValue<data_dict[k]):

           largeValue = data_dict[k]

           result = k

   return result

Following are the program on the dictionary:

Program:

def find_largest_value_key(data_dict):#defining a method find_largest_value_key that takes dictionary variable data_dict as a parameter

   m= max(data_dict.values())#defining a variable m that uses the max method that calculate the values from dictionary

   for k in data_dict.keys():#defining a loop that hold key values from dictionary

       if data_dict[k] == m:#defining if block that hold max value in dictionary

           return k#using the return keyword that return key value

data_dict={"sample": 15, 5: 25}#defining a dictionary that hold key and value

print(find_largest_value_key(data_dict))#using print method that calls find_largest_value_key method

Program Explanation:

  • Defining the method "find_largest_value_key" that takes "data_dict" as a dictionary variable inside the parameter.
  • Inside the method, "m" variable is declared that uses the "max" method that calculate the values from dictionary.
  • After calculating the value a for loop is declared that uses a "k" variable that hold key values from dictionary.
  • Inside the loop, an if block  is used that hold max value in dictionary and use the return keyword that return key value.
  • Outside the method dictionary is declared that calls the method by passing value into parameter.

Output:

Please find the attached file.

Findout the more information about the dictionary here:

brainly.com/question/26104476

Ver imagen codiepienagoya