title: Create a complicated form of dictionary with try and except
body: <p>I have been using list comprehension quite religiously throughout this project and finally I ran into a trouble where some elements do not have the range of index that is required.</p>
  <p>Here is my code for better understanding:</p>
  <pre class="lang-py prettyprint-override"><code>result_box_lst = [{
              &quot;coordinates&quot;: box['boundingPoly']['normalizedVertices'], 
              &quot;product&quot;: [{
                  &quot;product_name&quot;  : product[&quot;product&quot;][&quot;name&quot;],
                  &quot;product_uri&quot;   : product[&quot;product&quot;][&quot;img_uri&quot;],
                  &quot;price&quot;         : product[&quot;product&quot;][&quot;product_price&quot;],
  ###################### problematic area #############################################
                  &quot;product_label1&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][1][&quot;value&quot;],
                  &quot;product_label2&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][2][&quot;value&quot;],
                  &quot;product_label3&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][3][&quot;value&quot;],
  ######################################################################################
                  &quot;score&quot;         : product[&quot;score&quot;]
                  } for product in box['results'] if product[&quot;score&quot;] &gt;  0.25]
          } for box in grouped_results]
  </code></pre>
  <p>Here, the problem is that sometimes <code>product[&quot;product&quot;][&quot;productLables&quot;]</code> does not have multiple elements in the list so the list comprehension crashes with an <code>IndexOutofRange</code> exception. So I was thinking of catching it with try and except and googled it, but alas, list comprehensions can't have <code>try/except</code> within them.</p>
  <p>Thus I started coding in the basic way of doing for loop and got stuck wondering how I can create the same structure of complicated dictionary/list using the basic form of for loop. So far, I build this:</p>
  <pre class="lang-py prettyprint-override"><code>result_box_lst = []
  product = []
          for box in grouped_results:
              for product in box['results']:
                  if product[&quot;score&quot;] &gt;  0.25:
                      try:
  
                      products.append({
                          &quot;product_name&quot;: product[&quot;product&quot;][&quot;name&quot;],
                          &quot;product_uri&quot;   : product[&quot;product&quot;][&quot;img_uri&quot;],
                          &quot;price&quot;         : product[&quot;product&quot;][&quot;product_price&quot;],
                          &quot;product_label1&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][1][&quot;value&quot;],
                          &quot;product_label2&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][2][&quot;value&quot;],
                          &quot;product_label3&quot;: product[&quot;product&quot;][&quot;productLabels&quot;][3][&quot;value&quot;],
                          &quot;score&quot;         : product[&quot;score&quot;]
                      })
  
                      except:
                      pass
  </code></pre>
  <p>However, I am quite confident that this will never achieve what I wish. Is there any way to make such complicated dictionary/list with this for loop?</p>