[Tutor] Easy Problem

Sander Sweers sander.sweers at gmail.com
Tue Sep 1 14:46:33 CEST 2009


2009/9/1 Luke Paireepinart <rabidpoobear at gmail.com>:
>>>> txt = "Hi          how are you?"
>>>> " ".join(txt.strip().split())
> 'Hi how are you?'

txt.strip() only remove leading and trailing white space so does
nothing in your example. However it works because txt.split() removes
the excessive white space between the text.

>>> txt
'Hi          how are you?'
>>> ' '.join(txt.split())
'Hi how are you?'

Greets
Sander


More information about the Tutor mailing list