Question: code this as python coding CSc 120: Invert a Dictionary Expected Behavior Write a function invert_dict (origdict) that behaves as follows. Its argument origdict is
code this as python coding
CSc 120: Invert a Dictionary Expected Behavior Write a function invert_dict (origdict) that behaves as follows. Its argument origdict is a dictionary. This function returns a new dictionary constructed as follows: 1. Let origdict_keys be the list of the keys of origdict andorigdict_vals the list of the values that these keys are mapped to in origdict. 2. Construct a dictionary newdict with the tollowing properties: o The set of keys ot newdict is origdict_vals, and the set of values of nevdict is origdict_keys. o for any kin origdict_keys, if origdict[k]-val, then newdiet[ val k In other words, newdict is a mirror image of origdiet. In other words, invert_diet () inverts the mapping between keys and values. 3. Return the dictionary newdiet so constructed. Examples 1. Suppose ori gdict { a':12, 'b':93, .c':47}. Then the value returned by invert-dict is te dictionary . { 12:"a", 93: 'b', 471,c' 2. Let origdict345: pqr, 456: 'abc123: 'wxy, 234: ijk'. Then the value returned by this function is the dictionary pgr345 abc 456, xy 123, jk 234 3. Let origdict = { 1 1,2 2,33) ; , uvw. ( 1 1 ,4 3, 27 ) ; 'abc' ( 22, 1 1 , 19) ; . Im' } . Then the value returned by this function is the dictionary { "uvw . : [ 1 1 , 22, 33), 'abc . : { 11,43,27), "Inn " ;(22,11,19) }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
