[Tutor] creating the equivalent of string.strip()

Alan Gauld alan.gauld at btinternet.com
Wed Oct 3 08:12:11 CEST 2007


"Ricardo Aráoz" <ricaraoz at gmail.com> wrote

>sorry, forgot a piece of the code :
>
>s = list(s)
>while s[0].isspace() :
>     while s[-1].isspace() :
>         del s[-1]
>     del s[0]
> s = ''.join(s)

It still won't work. Strings are immutable, you can't use del
to delete a character. Try it.

>>> del('foo'[-1])
Traceback (most recent call last):
  File "<input>", line 1, in ?
TypeError: object doesn't support item deletion
>>>


Alan G. 




More information about the Tutor mailing list