Converting a list of lists to a single list

Rafael Durán Castañeda rafadurancastaneda at gmail.com
Wed Jul 24 00:34:31 CEST 2013


El 23/07/13 23:52, steve at divillo.com escribió:
> [[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]
Hi,

I think you are looking for itertools.chain, or in this case, 
itertools.chain.from_iterable:

In [1]: x = [['A0','A1','A2'], ['B0','B1','B2'], ['C0','C1','C2']]

In [2]: import itertools

In [3]: [ y for y in itertools.chain.from_iterable(x)]
Out[3]: ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2']

HTH



More information about the Python-list mailing list