transform a list of lists in a lit of strtings???

Troels Therkelsen t_therkelsen at hotmail.com
Sun Sep 8 21:03:25 CEST 2002


jubafre at brturbo.com wrote:
> I have a list of lists like this:
> 
> labels=[['D1'], ['D2'], ['D3']]
> 
> and i want to transform ia a list of strings
> 
> labels2==[ 'D1' ,  'D2' ,  'D3' ] <<<<<<<----------- how i can get it????
> 
> 	
> Juliano Freitas
> www.gebrasil.hpg.com.br 

labels2 = map(lambda x: x[0], labels)

or

labels2 = [ x[0] for x in labels ]


Whichever suits your fancy and/or programming style.

Regards,

Troels Therkelsen



More information about the Python-list mailing list