SyntaxFix
Write A Post
Hire A Developer
Questions
Try a regex with re.sub. You can search for all whitespace and replace with an empty string.
re.sub
\s in your pattern will match whitespace characters - and not just a space (tabs, newlines, etc). You can read more about it in the manual.
\s