Question: They gave the following hints: this function modifies the dictionary (removing elements from it) and does not return a value It is a bad idea

They gave the following hints: this function modifies the dictionary (removing elements from it) and does not return a value It is a bad idea to remove elements from the dictionary as you loop over it (why?). So we suggest that you first create a list of netids to drop, and then use this new list to drop elements from the dictionary.

def drop_below(adict,limit): """ Deletes all students in the dictionary with grades below limit. The dictionary adict has netids for keys and numbers 0-100 for values. These represent the grades that the students got on the exam. Examples: Suppose a = {'wmw2' : 55, 'abc3' : 90, 'jms45': 86} drop_below(a,60) changes a to {'abc3' : 90, 'jms45': 86} drop_below(a,90) changes a to {'abc3' : 90} drop_below(a,95) changes a to {} drop_below(a,50) leaves a unchanged as {'wmw2' : 55, 'abc3' : 90, 'jms45': 86} Parameter adict: the dictionary of grades Precondition: adict is dictionary mapping strings to ints Paramater limit: the cut-off boundary Precondition: limit is a number (int or float) """ # Hint: Create a list of netids to drop, and THEN drop them pass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!