Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need help with sorting a Python dictionary.

  1. Jul 21, 2011 #1
    1. The problem statement, all variables and given/known data

    Hi there,

    I need to sort a Python dictionary based on its values which are ints, then return the ordered list as the keys.

    I am thinking to make the inverse of the dictionary, take values and sort, then map back with the inverse dictionary.

    The problem is that when there are identical values, the inverse dictionary will not store the same value twice as the same key.. so a combination is lost.

    I tried to work around it by adding one to the value if the value is repeated, which should not change the sorting.. but am having trouble writing the code.

    Any help?

    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?