title: python check if item exist then print item
body: <p>i have a dictionary as such:</p>
  
  <pre><code>   my_dict= { documents : [{a:1,b:2},
                             {a:3},
                             {a:4,b:5}
                            ]
               }
  </code></pre>
  
  <p>I would like to print only the values of b.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>for item in my_dict[documents]:
      print item[b]
  </code></pre>
  
  <p>However this code keeps giving me an error probably because the key 'b' does not exist in every item.</p>
  
  <p>I changed my code to take into consideration of the exceptions:</p>
  
  <pre><code>for item in my_dict[documents]:
      if not item[b]:
          print "NONE"
      else:
          print item[b]
  </code></pre>
  
  <p>this doesnt seem to work. what do i need to change in my code to make it work?</p>
  
  <p>Thanks,</p>