title: Python: How to sort a list of dictionaries by several values?
body: <p>I want to sort a list at first by a value and then by a second value. Is there an easy way to do this? Here is a small example:</p>
  
  <pre><code>A = [{'name':'john','age':45},
       {'name':'andi','age':23},
       {'name':'john','age':22},
       {'name':'paul','age':35},
       {'name':'john','age':21}]
  </code></pre>
  
  <p>This command is for sorting this list by <code>'name'</code>:</p>
  
  <pre><code>sorted(A, key = lambda user: user['name'])
  </code></pre>
  
  <p>But how I can sort this list by a second value? Like <code>'age'</code> in this example.</p>
  
  <p>I want a sorting like this (first sort by <code>'name'</code> and then sort by <code>'age'</code>):</p>
  
  <pre><code>andi - 23
  john - 21
  john - 22
  john - 45
  paul - 35
  </code></pre>
  
  <p>Thanks!</p>