>>> import re >>> re.sub(' +', ' ', 'The quick brown fox') 'The quick brown fox'
" ".join([s for s in code.split(" ") if s])
string = "Welcome to Python" new_str = "".join(string.split(" ")) print(new_str) # "WelcometoPython"