title: Sort list of dictionaries in Python according to another list
body: <p>I have a list of dictionaries:</p>
  <pre><code>a = [{&quot;id&quot;: 5, &quot;data&quot;: &quot;data1&quot;}, {&quot;id&quot;: 2, &quot;data&quot;: &quot;data2&quot;}, {&quot;id&quot;: 10, &quot;data&quot;: &quot;data3&quot;}, {&quot;id&quot;: 121, &quot;data&quot;: &quot;data4&quot;}]
  </code></pre>
  <p>and a list of IDs:</p>
  <pre><code>ids_order = [10, 2, 5, 121]
  </code></pre>
  <p>I would like to reorder my list of dictionaries <code>a</code> so that my new list <code>new_a</code> have its dictionaries with value of the key &quot;id&quot; following the list <code>ids_order</code>:</p>
  <pre><code>new_a = [{&quot;id&quot;: 10, &quot;data&quot;: &quot;data3&quot;}, {&quot;id&quot;: 2, &quot;data&quot;: &quot;data2&quot;}, {&quot;id&quot;: 5, &quot;data&quot;: &quot;data1&quot;}, {&quot;id&quot;: 121, &quot;data&quot;: &quot;data4&quot;}]
  </code></pre>
  <p>Is there an efficient way to do it with the sort function? So far I am making a double loop to get the correct element, which is not especially the best. However, I couldn't find anything that could match with the sort function.</p>