# credit to the Stack Overflow user in the source link import re re.sub(' +', ' ', 'The quick brown fox') >>> 'The quick brown fox'