title: Sort a dictionary in python by values but maintaining the key order for equal values
body: <p>Lets say there is a dictionary</p>
  
  <pre><code>d = {"P1":77,"P2":89,"P3":77}
  </code></pre>
  
  <p>I want to print the results in following form </p>
  
  <p>P2: 89</p>
  
  <p>P1: 77</p>
  
  <p>P3: 77</p>
  
  <p>i.e. sorting by dictionary values and for equal values first one comes first(i.e P1 comes before P3)</p>
  
  <p>I did the following</p>
  
  <pre><code>import collections
  od = collections.OrderedDict(sorted(d.items(), key=lambda x:x[1], reverse=True))
  </code></pre>
  
  <p>od gives</p>
  
  <pre><code>OrderedDict([('P2', 89), ('P3', 77), ('P1', 77)])
  </code></pre>
  
  <p>How can I get P1 before P3 ?</p>