title: Most efficient method to check if dictionary key exists and process its value if it does
body: <pre><code>MyDict = {'key1':'value1', 'key2':'value2'}
  </code></pre>
  
  <p>I can do this few ways:</p>
  
  <pre><code>if 'key1' in MyDict:
         var1 = MyDict['key1']
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if MyDict.has_key('key1'):
         var1 = MyDict['key1']
  </code></pre>
  
  <p>or
  <strike></p>
  
  <pre><code>if MyDict['key1']:
      var1=MyDict['key1']
  </code></pre>
  
  <p></strike>
  or </p>
  
  <pre><code>try: 
     var1=MyDict['key1]
  except KeyError, e:
     pass
  </code></pre>
  
  <p>or I tried something like this but it does NOT WORK like this in python</p>
  
  <pre><code>if v=MyDict.get('key1'):
         var1=v
  </code></pre>
  
  <p>And we cold probably figure out lot more working ways to do that.
  Which one is most efficient in terms of computing speed?</p>