Flattening lists

Aahz aahz at pythoncraft.com
Thu Feb 5 13:24:13 EST 2009


In article <a22c77c4-a812-4e42-8972-6f3eedf72bb9 at l33g2000pri.googlegroups.com>,
Michele Simionato  <michele.simionato at gmail.com> wrote:
>
>Looks fine to me. In some situations you may also use hasattr(el,
>'__iter__') instead of isinstance(el, list) (it depends if you want to
>flatten generic iterables or only lists).

Of course, once you do that, you need to special-case strings...
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.



More information about the Python-list mailing list