title: Python: How to iterate lists of dictionaries Fast
body: <p>I'm using a following code to iterate through the lists of dictionaries to locate a corresponding key ['5'] and when found to compare the values. While it works fine I believe it could be improved to get a fast  performance. What other ways could be used to achieve the same result?</p>
  
  <pre><code>listA = [{1:'One', 2:'Two', 3:'Three'}, {4:'Four', 5:'Five', 6:'Six'}]
  listB = [{4:'Four', 5:'Five', 6:'Six'}, {7:'Seven', 8:'Eight', 9:'Nine'}]
  
  result=[]
  for dictA in listA:
      if not 5 in dictA.keys(): continue
      for dictB in listB:
          if 5 in dictB.keys() and dictB[5]==dictA[5]:
              result.append(dictB[5])
  </code></pre>