manipulate string

Eric Brunel eric.brunel at pragmadev.N0SP4M.com
Tue Oct 28 12:22:15 EST 2003


Michel Claveau/Hamster wrote:
> Like this :
> 
> 
>     import string
> 
>     a='0123456789'
>     l=list(a)
>     b=string.join(l,' - ')
>     print b

Apparently, the OP wants to discard characters at indexes 1, 3, 5, 7, etc... So, 
assuming Python version is 2.3, the correct solution seems to be:

 >>> a='0123456789'
 >>> print ' - '.join(a[::2])
0 - 2 - 4 - 6 - 8

HTH
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list