removing duplicate spaces from a string

Rich Harkins rharkins at
Mon Aug 6 22:38:26 CEST 2001

Since the default action of split is to seperate by white space (any number
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'


More information about the Python-list mailing list