title: Sort by values (descending) and then keys (ascending) in Python dictionary
body: <p>I have the following dictionaries:</p>
  
  <pre><code>mydict1 = {1: 11, 2: 4, 5: 1, 6: 1}
  mydict2 = {1: 1, 5: 1}
  </code></pre>
  
  <p>For each one of them I'd like to first sort by values (descending) and then keys (ascendingly), yielding this output:</p>
  
  <pre><code>out_dict1 = [((1, 11), (2, 4), (5, 1), (6, 1)]
  out_dict2 = [(1, 1), (5, 1)]
  </code></pre>
  
  <p>What's the way to do it?</p>
  
  <p>I used this but cannot get the result consistently for two cases above:</p>
  
  <pre><code>sorted(mydict.items(), key=lambda x: (x[1],x[0]))
  </code></pre>