Flattening lists

Mark Dickinson dickinsm at gmail.com
Thu Feb 5 10:21:22 EST 2009


On Feb 5, 1:17 pm, mk <mrk... at gmail.com> wrote:
> Hello everybody,
>
> Any better solution than this?
>
> def flatten(x):

Just out of interest, how often do people really need
such a recursive flatten, as opposed to a single-level
version?

I often find myself needing a 'concat' method that
turns a list of lists (or iterable of iterables) into
a single list;  itertools.chain does this quite nicely.
But I don't think I've ever encountered a need for the
full recursive version.

Mark




More information about the Python-list mailing list