I heed help in finishing this python code. It is supposed to read some given dic
ID: 3742008 • Letter: I
Question
I heed help in finishing this python code. It is supposed to read some given dictionary and with it you need to add the dictionarys keys and values into two list and sort them. once thats done, you make a new dictionary and put the sorted keys with the sorted values, but when I try to add the list its telling me that its unhashable
def shuffle_dict(somedict): sorted_keys- sorted_keys.append(somedict.keysO) sorted_values- sorted_values.append(somedict.values O sorted_keys.sortO sorted_values.sortO shuffle_dict- for i in range(len(somedict) shuffle_dictl sorted keys[i]1]-sorted_values[i] print(shuffle_dict) return shuffle_dict def main O shuffle_dict(f 345: 'par', 456: 'abc', 123: 'wxy, 234:'ijk']) mainOExplanation / Answer
def shuffle_dict(somedict): sorted_keys = sorted(somedict.keys()) sorted_values = sorted(somedict.values()) d = {} # you used shuffle_dict as dictionary name, but you already named your method as shuffle_dict. so, use something else for i in range(len(somedict)): d[sorted_keys[i]] = sorted_values[i] return d def main(): print(shuffle_dict({345: 'pqr', 456: 'abc', 123: 'wxy', 234: 'ijk'})) main()