[Tutor] function for removing all white spaces from a string
ricaraoz at gmail.com
Tue Oct 2 00:47:40 CEST 2007
> after reading the responses to athread in 2004  I am wondering why there is
> no easy function in python to remove all white spaces from a string.
> " i am very fine "
> In IDL there's just one simple function which does this: STRCOMPRESS .
> Is there really not yet such a function in Python?
> If not I created it:
> a = " i am very fine "
> def strcompress(mystring):
> ... mystring_compressed = ''.join(mystring.split())
> ... return mystring_compressed
> Thanks for your input,
>  Re: how to strip whitespaces from a string.
>  STRCOMPRESS http://idlastro.gsfc.nasa.gov/idl_html_help/STRCOMPRESS.html
''.join(c for c in a if not c.isspace())
More information about the Tutor