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

Discussion in 'Python' started by imperialguy, May 8, 2011.

  1. imperialguy

    imperialguy

    Joined:
    Apr 13, 2011
    Messages:
    5
    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?
    imperialguy, May 8, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper

    Is it possible to reorder a dataset?

    Shapper, Jun 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    604
    Brock Allen
    Jun 19, 2005
  2. farseer
    Replies:
    1
    Views:
    2,317
    farseer
    Jun 28, 2005
  3. plumb and tree
    Replies:
    7
    Views:
    364
    MrJean1
    Oct 30, 2007
  4. JohnE

    reorder list

    JohnE, Feb 6, 2010, in forum: ASP .Net
    Replies:
    2
    Views:
    745
    JohnE
    Feb 6, 2010
  5. Haim

    open a new window with ajax reorder list

    Haim, Jan 29, 2009, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    273
Loading...

Share This Page