Deleting characters from a string

Aahz Maruch aahz at
Sat Jun 5 22:32:47 CEST 1999

In article <y0jyahye89i.fsf at>,
Magnus L. Hetland <mlh at> wrote:
>result = ""
>for char in host:
>    if char not in ' "':
>        result = result+char
>host = result

That's a bad way to do it.  At the very least, that code should be
something like:

# There may be a couple of syntax errors below
result = []
for char in host:
    if char not in ' "':
host = string.join ( result, "" )

This has *much* better performance if host is at all long.
                      --- Aahz (

Hugs and backrubs -- I break Rule 6       <*>
Androgynous poly kinky vanilla queer het

"Why do you like my boyfriend to tie you up and beat me.?"
    -- ELIZA generates a poly moment

More information about the Python-list mailing list