title: How to handle KeyError only for some entries of the dictionary, not for all?
body: <p>I am building a table with data retrieved from sparql query. The problem is that some entries don't have value in the database, and when i am building the table, i get keyerror exception. How to handle the exception so that to put None in the fields where the exception is triggered? So far, the None values are being put on the whole row, but the exception exists only in one cell of that row...
  The python code is below:</p>
  <pre><code> for j in range(len(results['results']['bindings'])):  # effective results from database
                  try:
                      data.append([[results['results']['bindings'][j][results['head']['vars'][i]]['value']] for i in
                                   range(len(results['head']['vars']))])  
                  except KeyError:
                      data.append([None])  # get each line sepparately
  
  </code></pre>
  <p>The exception KeyError happens because some entries are NULL in the database, but the code is searching for them too. How to solve it?
  The actual table is below:
  <a href="https://i.stack.imgur.com/pZJBK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pZJBK.png" alt="enter image description here" /></a></p>
  <p>Here, only BatteryLife should be None, but the results are missing from the whole row.</p>