0

What is the best way for sorting an "associative" object in Python by value?

I have an object with associative key and float value:

data = {
    u'195': 1.33,
    u'716': 0.99,
    u'562': 0.53,
    u'310': 0.5900000000000001,
    u'88' : 0.7,
    u'426': 0.88
}

And I need:

data = {
    u'195': 1.33,
    u'716': 0.99,
    u'426': 0.88,
    u'88':  0.7,
    u'310': 0.5900000000000001,
    u'562': 0.53
}
alexwlchan
  • 5,699
  • 7
  • 38
  • 49
Andrea
  • 265
  • 1
  • 3
  • 13
  • It's not "associateive" object, it's dictionary. And it's unordered by "design". What do you want to do with it? – Jimilian Feb 18 '15 at 16:10
  • I have this dictionary from a json string (data=json.loads(string)) and i need sorting by value, how i can do it? – Andrea Feb 18 '15 at 16:14
  • there is no order in dictionary. you can try using list of tuples – taesu Feb 18 '15 at 16:17

0 Answers0