I have a dictionary with a specific order of keys(the values don't matter). I have another dictionary with the same keys, but not in the same order:
dict_1 = {"name" : "Joe", "class" : "8", "marks" : "80"}
dict_2 = {"class" : "9", "marks" : "90", "name" : "Adam"}
Now after sorting dict_2
, I want it to be as {"name" : "Adam", "class" : "9", "marks" : "90"}
. I know that this is possible since dictionaries are ordered by default in Python 3, but I couldn't get any solution even after a lot of research.
Edit: Another question is similar to this, and the answers given there could be used if the list to be based off is defined, in this case the keys of another dictionary(dict_1
). Answers here are more effecient