get_top_regions() that takes three input parameters; the 2-D list (similar to the database), the dictionary that stores information of all regions, and a non-zero positive integer x. This function returns a new dictionary that contains the information of top-x regions in terms of the total number of hospitalization cases recorded in these regions. That means these top-x regions have the largest numbers of hospitalization cases. Each {key:value} pair in this resulting dictionary stores the name of a top region as the key and the value is the total number of hospitalization cases reported in this region. The result does not need to be sorted, the regions of the resulting dictionary can appear in any order as long as the top-x regions have been identified correctly. If the value of x is less than 1, or more than the total number of unique regions, your function should print a message informing the user and return an empty dictionary. See sample outputs below. >>> topx_regions = get_top_regions(database, regions, 4) >>> display_dict(topx_regions) atlantic: 1131 none: 3570 north: 856 prairie: 4594 >>> topx_regions = get_top_regions(database, regions, 2) >>> display_dict(topx_regions) none: 3570 prairie: 4594
get_top_regions() that takes three input parameters; the 2-D list (similar to the
The result does not need to be sorted, the regions of the resulting dictionary can appear in any order as long as the top-x regions have been identified correctly. If the value of x is less than 1, or more than the total number of unique regions, your function should print a message informing the user and return an empty dictionary. See sample outputs below.
- >>> topx_regions = get_top_regions(database, regions, 4) >>> display_dict(topx_regions) atlantic: 1131 none: 3570 north: 856 prairie: 4594
>>> topx_regions = get_top_regions(database, regions, 2) >>> display_dict(topx_regions)
none: 3570
prairie: 4594>>> topx_regions = get_top_regions(database, regions, -5) >>> display_dict(topx_regions)
The value of x is too low or too high.
Dictionary is empty
Step by step
Solved in 2 steps