title: Python: Find matching records in two lists of dictionaries (different key names)
body: <p>I've got two lists of dictionaries with different keys but overlapping values, something like this:</p>
  
  <pre><code>list_a = [{key1: value_a, key2: value_b}, {key1: value_c, key2: value_d}, ...]
  list_b = [{key3: value_a, key4: value_z}, {key3: value_c, key4: value_z}, ...]
  </code></pre>
  
  <p>I want to join them together so that I can append <code>key4</code> to the <code>list_a</code> or indicate that there isn't a matching record found.</p>
  
  <p>I've been using a nested <code>for</code> loop to do this like:</p>
  
  <pre><code>for i in list_a:
      for v in list_b:
          if i["key1"] == v["key3"]:
              i["key4"] = v["key4"]
          else:
              i["key4"] = False
  </code></pre>
  
  <p>This doesn't seem very programmatically efficient since I have to loop through all of <code>list_b</code> for every <code>list_a</code> value. Is there a more efficient way of doing this?</p>
  
  <p>The actual data I'm working with is more complex so I've got a few conditions to match on in each list.</p>
  
  <p>I looked at list comprehensions, but wasn't sure which way to go with this.</p>
  
  <p>Any pointers (for this novice!) are appreciated!</p>
  
  <p>Edit: Expected output:</p>
  
  <pre><code>list_a = [{key1: value_a, key2: value_b, key4: value_z},
            {key1: value_c, key2: value_d, key4: value_z},
            {key1: value_e, key2: value_f, key4: False}, ...]
  </code></pre>
  
  <p>Basically find matching entries in <code>list_b</code> to <code>list_a</code> based on values, then update <code>list_a</code> with other k-v pairs from the matches or indicate a match wasn't found.</p>