title: Ternary operation on dictionary
body: <p>Is there a way to do a ternary operation on a dict where the test is has_key() without hitting the key error? i.e.</p>
  
  <pre><code>variable = dict["the_key"] if dict.has_key("the_key") else "something"
  </code></pre>
  
  <p>(this hits the key error obviously)</p>
  
  <p>failing that, what's the most pythonic way to assign a bunch of variables values based on a dict that may or may not have the keys in question? Repeating:</p>
  
  <pre><code>if dict.has_key('key'):
      value = dict['key']
  else:
      value = "value"
  </code></pre>
  
  <p>ad nauseum seems to be very inelegant.</p>