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

Michael Spencer mahs at telcopartners.com
Thu Mar 8 01:55:57 CET 2007


Sergio Correia wrote:
> spam = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
> 
> Into something like
> eggs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
> 
> There are *no* special cases (no empty sub-lists).
eggs = [i for j in spam for i in j]

Michael




More information about the Python-list mailing list