removing duplicate spaces from a string
Rajarshi Guha
rajarshi at seed.chem.psu.edu
Mon Aug 6 16:20:36 EDT 2001
Ron Johnson wrote:
> Say I have the strings:
> 'foo bar snafu'
> 'fiddle faddle pip pop'
>
> Are there any builtins that will allow me to compress the
> duplicate spaces out so that the files look like:
> 'foo bar snafu'
> 'fiddle faddle pip pop'
say the string is s, then you could proceed as follows:
o = ''
s = string.split(s,' ')
for i in s:
if (i != ' '):
o = o + i + ' '
This code segment will give you the final required ouput in o
--
Rajarshi Guha
More information about the Python-list
mailing list