How to strip all whitespace from string
Taking advantage of str.split’s behavior with no sep parameter: >>> s = ” \t foo \n bar ” >>> “”.join(s.split()) ‘foobar’ If you just want to remove spaces instead of all whitespace: >>> s.replace(” “, “”) ‘\tfoo\nbar’ Premature optimization Even though efficiency isn’t the primary goal—writing clear code is—here are some initial timings: $ python … Read more