You can remove all whitespaces from a string in Python using either string's replace method or regular expressions in the re module.
Using replace method:
main.py158 chars4 lines
Using re module:
main.py172 chars6 lines
In the second example, r"\s+" is a regular expression that matches one or more whitespace characters. sub method replaces all matches of this pattern with an empty string, effectively removing all whitespaces.
gistlibby LogSnag