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

Las Tutucas y todo lo demás

Python Ipdb Cheatsheet