Let's make some reasonable assumptions:
(1) You really want to replace any run of whitespace characters with a single space (a run is of length 1 or greater).
(2) You would like the same code to work with minimal changes under Python 2.X with unicode objects.
(3) You don't want your code to assume things that are not guaranteed in the docs
(4) You would like the same code to work with minimal changes with Python 3.X str objects.
The currently selected answer has these problems:
(a) changes " " * 3
to " " * 2
i.e. it removes duplicate spaces but not triplicate, quadruplicate, etc spaces. [fails requirement 1]
(b) changes "foo\tbar\tzot"
to "foobarzot"
[fails requirement 1]
(c) when fed a unicode object, gets TypeError: translate() takes exactly one argument (2 given)
[fails requirement 2]
(d) uses string.whitespace[:-1]
[fails requirement 3; order of characters in string.whitespace is not guaranteed]
(e) uses string.whitespace[:-1]
[fails requirement 4; in Python 2.X, string.whitespace is '\t\n\x0b\x0c\r '
; in Python 3.X, it is ' \t\n\r\x0b\x0c']
The " ".join(s.split())
answer and the re.sub(r"\s+", " ", s)
answer don't have these problems.