title: Python 3.6 : Sorting in Python vs Sorting in SQL
body: <p>I compared the order by of SQL and the built in function sorted() in python. I hoped that it gives me the same result but not.
  Here is the portion of SQL:<br/>
  <code>order by r.date, r.age_range, r.type_id asc;</code>
  and it gives me this :</p>
  
  <p>1
      2
      3
      4
      16
      5
      17
      6
      18
      7
      19
      8
      9
      10
      11
      12
      13
      14
      15</p>
  
  <p>(those are the Id i want).
  In python i used this code:</p>
  
  <pre><code>sorted(data, key=lambda r: (r.date, r.age_range, r.type_id))
  </code></pre>
  
  <p>and it gives me this : 1 2 3 16 4 17 5 18 6 7 19 8 9 10 11 12 13 14 15</p>
  
  <p>(Problem with the last criteria (r.type_id)). Can someone explain me and help me? Thank you.</p>
  
  <p>Ps : data is list of object; date is string; age is integer; type is integer also. <br/>
  The result i want: </p>
  
  <p><a href="https://i.stack.imgur.com/Hg2Vg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hg2Vg.png" alt="enter image description here"></a></p>