removing text string

Wojtek Walczak gminick at bzt.bzt
Wed Sep 10 20:14:21 CEST 2008


On Wed, 10 Sep 2008 11:22:16 -0400, Ahmed, Shakir wrote:
> I need to remove text string from the list of the numbers mentioned
> below:
>
> 080829-7_A
> 070529-5_c
> 080824-7_O
> 070405_6_p
>
> The output will be : 080829-7
>                      070529-5
> 		         080824-7
>                      070405-6    		                       

You need to read about slice indices. An example:

>>> a=('080829-7_A', '070529-5_c', '080824-7_O')
>>> [i[:-2] for i in a]
['080829-7', '070529-5', '080824-7']


-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/



More information about the Python-list mailing list