>>> import re >>> re.sub("\s+"," ","some user entered text") 'some user entered text' >>>
EDIT:
It will also replace line breaks and tabs, etc.
If you specifically want to use spaces / tabs, you can use
>>> import re >>> re.sub("[ \t]+"," ","some user entered text") 'some user entered text' >>>
source share