title: Python safe dictionary key access
body: <p>I am looking for a convenient, safe python dictionary key access approach. Here are 3 ways came to my mind.</p>
  
  
  
  <pre class="lang-py prettyprint-override"><code>data = {'color': 'yellow'}
  
  # approach one
  color_1 = None
  if 'color' in data:
      color_1 = data['color']
  
  # approach two
  color_2 = data['color'] if 'color' in data else None
  
  
  # approach three
  def safe(obj, key):
      if key in obj:
          return obj[key]
      else:
          return None
  
  color_3 = safe(data, 'color')
  
  #output
  print("{},{},{}".format(color_1, color_2, color_3))
  </code></pre>
  
  <p>All three methods work, of-course. But is there any simple out of the box  way to achieve this without having to use excess <code>if</code>s or custom functions?</p>
  
  <p>I believe there should be, because this is a very common usage.</p>