title: Sorting a dictionary by value with tuples as values
body: <p>I have a dictionary with the following structure:</p>
  <pre><code>Key   = A tuple containing two strings
  Value = A tuple containing two float values
  </code></pre>
  <p>I want to sort this dictionary using both values.</p>
  <p>The requirement is to pick the top 10 records with maximum values for both float fields</p>
  <p>Is it possible to do so?</p>
  <p>Please find below a sample of the data in dictionary:</p>
  <pre><code>{&quot;(12144, 'DBI 3900288')(62232, 'DBI 9503371')&quot;: (0.2978723404255319, 56),
   &quot;(62232, 'DBI 9503371')(12144, 'DBI 3900288')&quot;: (0.45153846153846154, 56),
   &quot;(89121, 'USB 7812')(908121, 'USB 3182')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20629, 'FORT 11156')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20630, 'FORT 11158')&quot;: (0.9, 9),
   &quot;(908121, 'USB 3182')(20632, 'FORT 11164')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20666, 'FORT 1234TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20667, 'FORT 1236TOB')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20669, 'FORT 1240TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20674, 'FORT 1252TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20675, 'FORT 1258TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20684, 'FORT 13408A')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20685, 'FORT 13410A')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20686, 'FORT 13412A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20687, 'FORT 13415A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20688, 'FORT 13418A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20689, 'FORT 13424A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20711, 'FORT 16-630')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20712, 'FORT 16-632')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20713, 'FORT 16-634')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20714, 'FORT 16-636')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20716, 'FORT 16-640')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20972, 'FORT 39002')&quot;: (0.9, 9),
   &quot;(908121, 'USB 3182')(20985, 'FORT 39652')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20987, 'FORT 39658')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20992, 'FORT 39670')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20993, 'FORT 39672')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20995, 'FORT 39676')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20996, 'FORT 39682')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20999, 'FORT 39688')&quot;: (0.45, 6) }
  </code></pre>
  <p>Expected Output:</p>
  <pre><code>{
  
   &quot;(908121, 'USB 3182')(20630, 'FORT 11158')&quot;: (0.9, 9),
   &quot;(908121, 'USB 3182')(20972, 'FORT 39002')&quot;: (0.9, 9),
   &quot;(908121, 'USB 3182')(20629, 'FORT 11156')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20666, 'FORT 1234TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20669, 'FORT 1240TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20674, 'FORT 1252TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20675, 'FORT 1258TOB')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20711, 'FORT 16-630')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20716, 'FORT 16-640')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20985, 'FORT 39652')&quot;: (0.8, 8),
   &quot;(908121, 'USB 3182')(20684, 'FORT 13408A')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20685, 'FORT 13410A')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20712, 'FORT 16-632')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20714, 'FORT 16-636')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20995, 'FORT 39676')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20996, 'FORT 39682')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20987, 'FORT 39658')&quot;: (0.7, 7),
   &quot;(908121, 'USB 3182')(20992, 'FORT 39670')&quot;: (0.7, 7), 
  &quot;(62232, 'DBI 9503371')(12144, 'DBI 3900288')&quot;: (0.45153846153846154, 56),
   &quot;(908121, 'USB 3182')(20632, 'FORT 11164')&quot;: (0.45, 6),
   &quot;(89121, 'USB 7812')(908121, 'USB 3182')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20667, 'FORT 1236TOB')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20686, 'FORT 13412A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20687, 'FORT 13415A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20688, 'FORT 13418A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20689, 'FORT 13424A')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20713, 'FORT 16-634')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20999, 'FORT 39688')&quot;: (0.45, 6),
   &quot;(908121, 'USB 3182')(20993, 'FORT 39672')&quot;: (0.45, 6)
   &quot;(12144, 'DBI 3900288')(62232, 'DBI 9503371')&quot;: (0.2978723404255319, 56),
   }
  </code></pre>
  <p>When the sorting method is used on the float values of the tuple. The sorting order is sometimes mixed up when the second float value in the tuple is double digit. For e.g. in the example shown below, sorting of 1st float is perfectly in desc order, however, the second float sorting is incorrect as 8 &lt; 15</p>
  <pre><code> &quot;(12423, 'LACT 1281')(14961, 'OSI 76214')&quot;: (0.8888888888888888, 8),
   &quot;(12423, 'LACT 1281')(15328, 'PER 58835')&quot;: (0.8888888888888888, 8),
   &quot;(12423, 'LACT 1281')(16902, 'RAP NRT16')&quot;: (0.8888888888888888, 8),
   &quot;(18154, 'TGIS 804176-01')(18139, 'TGIS 57264-00')&quot;: (0.8823529411764706, 15),
   &quot;(3034, 'TIME 08121')(2926, 'TIME 15677')&quot;: (0.8823529411764706, 15),
   &quot;(3034, 'TIME 08121')(2927, 'TIME 16424')&quot;: (0.8823529411764706, 15),
  </code></pre>