title: Flatten an irregular (arbitrarily nested) list of lists
body: <p>Yes, I know this subject has been covered before:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/120886">Python idiom to chain (flatten) an infinite iterable of finite iterables?</a></li>
  <li><a href="https://stackoverflow.com/questions/406121">Flattening a shallow list in Python</a></li>
  <li><a href="https://stackoverflow.com/questions/457215">Comprehension for flattening a sequence of sequences?</a></li>
  <li><a href="https://stackoverflow.com/questions/952914">How do I make a flat list out of a list of lists?</a></li>
  </ul>
  <p>but as far as I know, all solutions, except for one, fail on a list like <code>[[[1, 2, 3], [4, 5]], 6]</code>, where the desired output is <code>[1, 2, 3, 4, 5, 6]</code> (or perhaps even better, an iterator).</p>
  <p>The only solution I saw that works for an arbitrary nesting is found <a href="https://stackoverflow.com/questions/406121">in this question</a>:</p>
  <pre><code>def flatten(x):
      result = []
      for el in x:
          if hasattr(el, &quot;__iter__&quot;) and not isinstance(el, basestring):
              result.extend(flatten(el))
          else:
              result.append(el)
      return result
  </code></pre>
  <p>Is this the best approach? Did I overlook something? Any problems?</p>