0

I have a dictionary with integers for both keys and values

d = {25:5, 12:45, 34:5, 19:5, 209:3, 12:7, 1:999, 999:1}

Is there a method to return

>>> print d
{999:1, 209:3, 19:5, 25:5, 34:5, 12:7, 12:45, 1,999}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Dictionaries have no order. You can produce a list of the keys or of the values or of the keys and values together, but not another dictionary. – Martijn Pieters Jun 15 '15 at 15:03
  • [Sort a Python dictionary by value](http://stackoverflow.com/q/613183) tells you how to produce such a sorted sequence; substitute `itemgetter(1)` with `itemgetter(1, 0)` to include the key for the secondary sort. – Martijn Pieters Jun 15 '15 at 15:04

0 Answers0