-3

I have a dictionary like this.

d = {'"mn': '800"', '"kl': '700"', '"ng': '1100"'}

How to sort this into descending order. like below

ng,1100

mn,800

kl,700
Nicolas78
  • 5,124
  • 1
  • 23
  • 41
  • As an aside, where did that dictionary come from? There are quotation marks on the left of each key, and on the right of each value, which makes it feel like the source was parsed incorrectly. – DSM May 01 '14 at 14:09

2 Answers2

1

You can user OrderedDict for that.

reverse_dictionary = OrderedDict(reversed(sorted(d.items())), key=lambda t: t[1])
fatiherdem
  • 1,173
  • 6
  • 18
  • 35
0

Im not sure what you mean, a dictionary by definition is unsorted. you may want to use an array of dictionaries.

Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43