remove redundant spaces python code example
Example 1: remove multiple space python
import re
re.sub(' +', ' ', 'The quick brown fox')
'The quick brown fox'
Example 2: how to remove spaces in string in python
sentence = ' hello apple '
sentence.strip()
>>> 'hello apple'
Example 3: remove duplicate space in string in pytoon
>>> import re
>>> re.sub(' +', ' ', 'The quick brown fox')
'The quick brown fox'