Question: Write a function shuffle _ dict ( somedict ) that behaves as follows. Its argument somedict is a dictionary. This function returns a new dictionary
Write a function shuffledictsomedict that behaves as follows. Its argument somedict is a dictionary. This function returns a new dictionary constructed as follows:
Let sortedkeys be the sorted list of the keys of somedict.
Let sortedvals be the sorted list of the values that these keys are mapped to in somedict.
Construct a dictionary shuffleddict that maps sortedkeys to sortedvals sortedkeys to sortedvals sortedkeys to sortedvals sortedkeysn to sortedvalsn
Return the dictionary shuffleddict so constructed.
Note: You can get the set of values in a dictionary somedict using somedict.values This is analogous to the keys method that gives the keys in a dictionary. In each case, you then need to use list to obtain a list.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
