[Tutor] creating the equivalent of string.strip()
ricaraoz at gmail.com
Wed Oct 3 12:49:07 CEST 2007
Alan Gauld wrote:
> "Ricardo Aráoz" <ricaraoz at gmail.com> wrote
>> sorry, forgot a piece of the code :
>> s = list(s)
>> while s.isspace() :
>> while s[-1].isspace() :
>> del s[-1]
>> del s
>> s = ''.join(s)
> It still won't work. Strings are immutable, you can't use del
> to delete a character. Try it.
It comes straight from Idle (still warm ;-) ). Notice s = list(s) and s
= ''.join(s), so I'm not using del with strings but with a list and that
is ok. Try it, it does work.
> Traceback (most recent call last):
> File "<input>", line 1, in ?
> TypeError: object doesn't support item deletion
Not what I'm doing.
More information about the Tutor