Удалить все пробелы из String Python
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
Helpful Hippopotamus
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
>>> s = " \t foo \n bar "
>>> "".join(s.split())
'foobar'