list problem

Terry Reedy tjreedy at udel.edu
Tue Sep 24 03:04:46 CEST 2002


<jubafre at brturbo.com> wrote in message
news:mailman.1032818129.8126.python-list at python.org...
> i have:
> x=[['0020', '0000x9'], ['0030', '0000xa'], ['00B4', '0000x8'],
['0030', '0000xb'], ['00F0'], ['0001'], ['0003'], ['0005']]
>
> and i want:
> y=['0020', '0000x9', '0030', '0000xa', '00B4', '0000x8', '0030',
'0000xb','00F0', '0001',
> '0003', '0005']
>
> how to do this?
>>> [b for a in  x for b in a]
['0020', '0000x9', '0030', '0000xa', '00B4', '0000x8', '0030',
'0000xb', '00F0',
 '0001', '0003', '0005']

For deeper flattening, try google: Python list flatten

Terry J. Reedy





More information about the Python-list mailing list