Question: PYTHON3 SOLUTION PLEASE! Suppose we have two dictionaries with student ids and scores attached to them for two different assignments. We want to combine these

PYTHON3 SOLUTION PLEASE!

Suppose we have two dictionaries with student ids and scores attached to them for two different assignments. We want to combine these two dictionaries into one big dictionary that has the overarching scores across the assignments, however, some students didn't turn in one or the other assignments, so we cannot simply convert to lists and add. We want you to write a function called dict_mergethat takes in two dictionaries that might have overlapping keys and return one combined dictionary that has all of the keys from each dictionary and added the scores of each overlapping ID.

dict1, dict2: a dictionaries that map student id to a score.

return: a dictionary of student ids mapped to scores with identical student ids having their scores added.

>>> dict2 = all_at_once([1,7,5,4,3],triple)

>>> dict1 = all_at_once([1,4,5,6],square)

>>> dict_merge(dict1,dict2)

{1: 4, 3: 9, 4: 28, 5: 40, 6: 36, 7: 21}

>>> dict1 = {"a118":47,"a192":53,"u111":77}

>>> dict2 = {"u111":11.5,"a192":69.8,"a117":12}

>>> dict_merge(dict1,dict2)

{'a117': 12, 'a118': 47, 'a192': 122.8, 'u111': 88.5}

>>> dict_merge({},{})

{}

>>> dict_merge({},{1:7,2:5})

{1: 7, 2: 5}

>>> dict_merge({1:3},{1:7,2:5})

{1: 10, 2: 5}

Notes:

Student ID can be either an int or a string. In other words, for each run the input dictionaries can contain either integers is IDs or strings as IDs. They cannot be mixed.

Score has to be an int or a float.

The output dictionary has to be sorted with ID in alphabetical or numerical order

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!