whitespace
Tim Rowe
tim at remove_if_not_spam.digitig.co.uk
Fri Sep 19 20:05:51 EDT 2003
On Fri, 19 Sep 2003 19:35:54 -0400, "RR" <rr84 at cornell.edu> wrote:
>Is there an easy way in python to remove whitespace from a string?
>From the ends or all of it?
>From the ends,
" hello ".strip()
gives "hello"
There are lstrip and rstrip if you only want to strip from one end.
To get rid of all whitespace I'd probably do:
import string
string.join(" hello there world ".split(), "")
which gives
'hellothereworld'
Though there may be an easier way.
More information about the Python-list
mailing list