Python - Sort a list of dics by value of dict`s dict value
<p>I have a list that looks like this:</p>

<pre><code>persons = [{'id': 11, 'passport': {'id': 11, 'birth_info':{'date': 10/10/2016...}}},{'id': 22, 'passport': {'id': 22, 'birth_info':{'date': 11/11/2016...}}}]
</code></pre>

<p>I need to sort the list of persons by their sub key of sub key - their birth_info date.</p>

<p>How should I do it ?
Thanks</p>

<p>The function <code>sorted()</code> provides the <code>key</code> argument. One can define a callable which returns the key to compare the items:</p>

<pre><code>sorted(persons, key=lambda x: x['passport']['birth_info']['date'])
</code></pre>

<p>The argument x is an item of the given list of persons. </p>

<p>If the dates are strings you could use the <code>datetime</code> module:</p>

<pre><code>sorted(persons, key=lambda x: datetime.datetime.strptime(x['passport']['birth_info']['date'], '%m/%d/%Y'))
</code></pre>

python list sorting quicksort