removing duplicate spaces from a string

Ron Johnson ron.l.johnson at
Mon Aug 6 10:24:49 CEST 2001


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").


| Ron Johnson, Jr.        Home: ron.l.johnson at       |
| Jefferson, LA  USA       |
|                                                            |
| "Our computers and their computers are the same color. The |
|  conversion should be no problem!"                         |
|    Unknown                                                 |

More information about the Python-list mailing list