title: Check for the presence of a key/value pair in a Python dictionary
body: <p>What is the shortest way to check for the existence of a certain key/value pair in a dictionary if I don't know that the key exists?</p>
  
  <p>So far, I've come up with:</p>
  
  <pre><code>if 'key' in my_dict and my_dict['key'] == 'value':
      do_something()
  </code></pre>
  
  <p>This is really long with longer variable names or longer key/value names, such as:</p>
  
  <pre><code>if 'X-Powered-By' in self.request.headers and self.request.headers['X-Powered-By'] == 'NodeBB':
      do_something()
  </code></pre>
  
  <p>What's a shorter way to check for the presence of a key and a corresponding value?</p>