Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

image text in transcribed
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 merge that 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 input: 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. def dict merge (dict one, dict two): "Merges two dictionaries, summing matching labels. >>> dict2 (1:3,7:21,5:15,4:12,3:9) >>> dict1(l:1,4:16,5:25,6:36) >> new dict dict nerge(dictl,dict2) >(key, new dikey]) for key in sorted(new dict.keys ())1 (1, 4), (3, 9), (4, 28), (5,40), (6, 36), (7, 21)1 >>> dictl1a118 :47, -a19253, ul1i":77 >> dict2 (ul11":11.5, "a192:69.8,"a117:12) > new dict dict merge(dicti,dict2) >(key, new dict [key]) for key in sorted(new dict. keys ())1 t ('ail7", 12), ('a118, 47), (a192,122.8), (ulll', 88.5)1 >>> dict nerge((0,) th >>> new dict dict merge(,17,2:5) > (key, new dict [ key]) for key in sorted(nev dict.keys())1 >>> new dict dict merge( (1:3) (1:7,2:5)) >[(key, new dict[key]) for key in sorted(new dict. keys())1 10), (2, 5)1 # YOUR CODE HERE otes . Student ID can be either an int or a string. In other words, for each run the input dictionaries can contain either integers as IDs or strings as IDs. They cannot be mixed. Score has to be an int or a float

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

Students explore these related Databases questions