Hello,
after reading the responses to athread in 2004 [1] I am wondering why there is
no easy function in python to remove all white spaces from a string.

Like:

" i am very fine "
to
"iamveryfine"

In IDL there's just one simple function which does this: STRCOMPRESS [2].

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

 strcompress(a)
'iamveryfine'

Thanks for your input,
Timmie

[1] Re: how to strip whitespaces from a string.
http://article.gmane.org/gmane.comp.python.tutor/18622

[2] STRCOMPRESS http://idlastro.gsfc.nasa.gov/idl_html_help/STRCOMPRESS.html

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to