>>> print "".join(" hello   world ".split())
helloworld

The key to the above is that the String method split() separates the string on any amount of whitespace when no separator is specified.

Python Logo