Flatten a two-level list --> one liner?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 7 19:51:27 EST 2007


En Wed, 07 Mar 2007 21:41:16 -0300, Sergio Correia  
<sergio.correia at gmail.com> escribió:

> I forgot to say: I've already checked the discussions about
> recursive/iterative/etc flatten() functions that can sweep through a
> list of arbitrary length, but that's really overkill for what I want.
>
> However, "sum(eggs, [])" or itertools seem to do it w/out the need for
> a new function.
>
> Thanks a lot!

Just for being (a little!) constructive, given your preconditions on the  
list, you can use:
eggs = [item for sublist in spam for item in sublist]

-- 
Gabriel Genellina




More information about the Python-list mailing list