title: Comparing dictionaries in Python
body: <p>Given two dictionaries, <code>d1</code> and <code>d2</code>, and an integer <code>l</code>, I want to find all keys <code>k</code> in <code>d1</code> such that either <code>d2[k]&lt;l</code> or <code>k not in l</code>. I want to output the keys and the corresponding values in <code>d2</code>, except if <code>d2</code> does not contain the key, I want to print 0. For instance, if <code>d1</code> is </p>
  
  <pre><code>a: 1
  b: 1
  c: 1
  d: 1
  </code></pre>
  
  <p>and <code>d2</code> is</p>
  
  <pre><code>a: 90
  b: 89
  x: 45
  d: 90
  </code></pre>
  
  <p>and <code>l</code> is 90, the output would be (possibly in a different order)</p>
  
  <pre><code>b 89
  c 0
  </code></pre>
  
  <p>What is the best way to do this in Python? I am just starting to learn the language, and so far this is what I have:</p>
  
  <pre><code>for k in d1.keys():
      if k not in d2:
          print k, 0
      else:
          if d2[k]&lt;l:
              print k, d2[k]
  </code></pre>
  
  <p>This works of course (unless I have a typo), but it seems to me that there would be a more pythonic way of doing it.</p>