-2

I think I made an overly complicated question regarding order of dictionaries, so I have simplified it to a simpler question

Let's say I have the dictionary

d1= {570.44: 2, 305.21: 1, 271.94: 0, 463.20: 3, 556.60: 4, 596.27: 5}

I want to get an ordered list of the keys but ordered according to the values not the keys

In this case I would like to get

[271.94, 305.21, 570.44, 463.20, 556.60, 596.27]

(since you can see that their values are: 0,1,2,3,4,5

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

1 Answers1

2

Try this:

d1= {570.44: 2, 305.21: 1, 271.94: 0, 463.20: 3, 556.60: 4, 596.27: 5}

sorted(d1, key=d1.get)

Output:

[271.94, 305.21, 570.44, 463.2, 556.6, 596.27]
I'mahdi
  • 23,382
  • 5
  • 22
  • 30