title: What is the fastest way to access elements in a nested list?
body: <p>I have a list which is made up out of three layers, looking something like this for illustrative purposes:</p>
  
  <pre><code>a = [[['1'],['2'],['3'],['']],[['5'],['21','33']]]
  </code></pre>
  
  <p>Thus I have a top list which contains several other lists each of which again contains lists.</p>
  
  <p>The first layer will contain in the tens of lists. The next layer could contain possibly millions of lists and the bottom layer will contain either an empty string, a single string, or a handful of values (each a string).</p>
  
  <p>I now need to access the values in the bottom-most layer and store them in a new list in a particular order which is done inside a loop. What is the fastest way of accessing these values? The amount of memory used is not of primary concern to me (though I obviously don't want to squander it either).</p>
  
  <p>I can think of two ways:</p>
  
  <ol>
  <li>I access list <code>a</code> directly to retrieve the desired value, e.g. <code>a[1][1][0]</code> would return <code>'21'</code>.</li>
  <li>I create a copy of the elements of <code>a</code> and then access these to flatten the list a bit more. In this case thus, e.g.: <code>b=a[0]</code>, <code>c=a[1]</code>  so instead of accessing <code>a[1][1][0]</code> I would now access <code>b[1][0]</code> to retrieve <code>'21'</code>.</li>
  </ol>
  
  <p>Is there any performance penalty involved in accessing nested lists? Thus, is there any benefit to be gained in splitting list <code>a</code> it into separate lists or am I merely incurring a RAM penalty in doing so?</p>