title: Test if dict contained in dict
body: <p>Testing for equality works fine like this for python dicts:</p>
  
  <pre><code>first  = {"one":"un", "two":"deux", "three":"trois"}
  second = {"one":"un", "two":"deux", "three":"trois"}
  
  print(first == second) # Result: True
  </code></pre>
  
  <p>But now my second dict contains some additional keys I want to ignore:</p>
  
  <pre><code>first  = {"one":"un", "two":"deux", "three":"trois"}
  second = {"one":"un", "two":"deux", "three":"trois", "foo":"bar"}
  </code></pre>
  
  <p><strong>Is there a simple way to test if the first dict is part of the second dict, with all its keys and values?</strong></p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>This question is suspected to be a duplicate of <a href="https://stackoverflow.com/questions/3415347/how-to-test-if-a-dictionary-contains-certain-keys">How to test if a dictionary contains certain <em>keys</em></a>, but I'm interested in testing keys <em>and their values</em>. Just containing the same keys does not make two dicts equal.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>OK, I got some answers now using four different methods, and proved all of them working. As I need a fast process, I tested each for execution time. I created three identical dicts with 1000 items, keys and values were random strings of length 10. The <code>second</code> and <code>third</code> got some extra key-value pairs, and the last non-extra key of the <code>third</code> got a new value. So, <code>first</code> is a subset of <code>second</code>, but not of <code>third</code>. Using module <code>timeit</code> with 10000 repetitions, I got:</p>
  
  <pre><code>Method                                                      Time [s]   
  first.viewitems() &lt;=second.viewitems()                           0.9 
  set(first.items()).issubset(second.items())                      7.3
  len(set(first.items()) &amp; set(second.items())) == len(first)      8.5
  all(first[key] == second.get(key, sentinel) for key in first)    6.0
  </code></pre>
  
  <p>I guessed the last method is the slowest, but it's on place 2. 
  But method 1 beats them all.</p>
  
  <p>Thanks for your answers!</p>