Not claiming to be the fastest, but here are two Python solutions suggested by Dave Beazley [0], plus one I extended using compiled regular expressions:
# string replacement
s = ' hello world \n'
s.replace(' ', '')
# 'helloworld'
# regular expression
import re
re.sub('\s+', '', s)
# 'helloworld'
# compiled regular expression
pat = re.compile('\s+')
pat.sub('', s)
# 'helloworld'