0
dict = {a:{x:2,y:2}, b:{x:0,y:2}, c:{x:2,y:0}, d:{x:0,y:0}}

I want to sort a dictionary like this based on increasing order of 'y' and then decreasing order of 'x' and return the keys.

I found a similar question here- Sort nested dictionary by value, and remainder by another value, in Python, but I want to know how to apply reverse sort on only one of the values.

  • Dictionaries are inherently unordered, so what exactly is the output you are expecting for your "sorted dictionary"? – juanpa.arrivillaga Oct 27 '17 at 17:57
  • `sorted(dict.items(), key=lambda kv: (kv[1]['y'], -kv[1]['x']))` will give you a sorted list of `(key, value)` pairs, sorted in the order you want (increasing on `y`, for ties decreasing on `x`, so `c`, `d`, `a`, `b`). – Martijn Pieters Oct 27 '17 at 17:59
  • @Ghostly Martijn Thankyou! That '-' solved the issue I had. – user8844941 Oct 27 '17 at 18:22

0 Answers0