- Joined
- Apr 13, 2011
- Messages
- 5
- Reaction score
- 0
Let us consider a dictionary:
I want to re-order this dictionary in an order specified by a list containing the order of the dictionary keys that I desire. Let us say the desired order list is:
So, I want my dictionary to appear like this:
How do I achieve this in the least complex way possible?
Code:
sample_dict={1:'r099',2:'g444',3:'t555',4:'f444',5:'h666'}
Code:
desired_order_list=[5,2,4,3,1]
So, I want my dictionary to appear like this:
Code:
{5:'h666',2:'g444',4:'f444',3:'t555',1:'r099'}
How do I achieve this in the least complex way possible?