removing duplicate spaces from a string

Alex Martelli aleaxit at
Tue Aug 7 18:07:37 CEST 2001

"Rich Harkins" <rharkins at> wrote in message
news:mailman.997130350.25505.python-list at
> Since the default action of split is to seperate by white space (any
> or type of white space will do), the following one liner would do:
> >>> s='a  b c  d'
> >>> ' '.join(s.split())
> 'a b c d' long as you're real *SURE* that s doesn't contain
OTHER forms of whitespace, such as tabs or newlines, or
you're OK with them mutating into spaces...


More information about the Python-list mailing list