title: Custom sort list of dictionaries by other dictionary or list
body: <p>I have a list of dictionaries that I would like to order based on an external ordering (list, dictionary, whatever works). Let's say I have the following list:</p>
  <pre><code>list_a = [{&quot;dylan&quot;: &quot;alice&quot;}, {&quot;arnie&quot;: &quot;charles&quot;}, {&quot;chelsea&quot;: &quot;bob&quot;}]
  </code></pre>
  <p>and I want to sort it like this</p>
  <pre><code>sorted_list_a = [{&quot;arnie&quot;: &quot;charles&quot;}, {&quot;chelsea&quot;: &quot;bob&quot;}, {&quot;dylan&quot;: &quot;alice&quot;}]
  </code></pre>
  <p>I've tried to do it like this:</p>
  <pre><code># list_a will have a variable number of dictionaries all with unique keys
  # list_order will have all dictionary keys ordered, even if they don't appear in list_a
  list_order = [{&quot;arnie&quot;: 1}, {&quot;britta&quot;: 2}, {&quot;chelsea&quot;: 3}, {&quot;dylan&quot;: 4}]
  list_a.sort(key=lambda x: list_order[x.keys()])
  </code></pre>
  <p>but I get <code>TypeError: list indices must be integers or slices, not dict_keys</code>. I feel like I'm close, but I can't quite get to the end.</p>