Reorder dictionary in pyrhon according to a list of values!!!

Joined
Apr 13, 2011
Messages
5
Reaction score
0
Let us consider a dictionary:
Code:
sample_dict={1:'r099',2:'g444',3:'t555',4:'f444',5:'h666'}
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:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top