removing duplicate spaces from a string

Ron Johnson ron.l.johnson at home.com
Mon Aug 6 04:24:49 EDT 2001


Hello,

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'

I could iteratively apply string.replace, replacing '  ' with 
' ', but that doesn't seem the optimum course.

For anyone with VMS experience, I want to emulate the DCL lexical
function F$EDIT("COMPRESS").

Sincerely,
Ron

+------------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson at home.com       |
| Jefferson, LA  USA      http://ronandheather.dhs.org       |
|                                                            |
| "Our computers and their computers are the same color. The |
|  conversion should be no problem!"                         |
|    Unknown                                                 |
+------------------------------------------------------------+



More information about the Python-list mailing list