Removing white spaces in Python

Using split()
in = " something     with multiple white spaces   "
parsed = in.split()
output = ' '.join(in)
Using regular expresions
import re
in =  " something     with multiple white spaces   "
output = re.sub("\s+" , " ", in)


Comments

Popular posts from this blog

Como configurar el control de directv para que funcione con el Tv

Could not activate celullar data network - Iphone - Movistar

Show all values in Numpy array