What is the fastest way to flatten arbitrarily nested lists in Python?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/406121/flattening-a-shallow-list-in-python">Flattening a shallow list in Python</a><br>
  <a href="http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python">Flatten (an irregular) list of lists in Python</a>  </p>
</blockquote>



<p>I've found solutions before, but I'm wondering what the fastest solution is to flatten lists which contain other lists of arbitrary length.</p>

<p>For example:</p>

<pre><code>[1, 2, [3, 4, [5],[]], [6]]
</code></pre>

<p>Would become:</p>

<pre><code>[1,2,3,4,5,6]
</code></pre>

<p>There can be infinitely many levels, so the solution would probably need to be implemented recursively.</p>

<p>Ideally, empty lists would be ignored like in the example above (no exceptions and errors). I expect this behaviour would emerge as a result of a neat recursive solution anyway.</p>

<p>Something else which doesn't affect me now, but I don't want to ignore is that some of the list objects can be strings, which mustn't be flattened into their sequential characters in the output list.</p>
