Deleting specific characters from a string

Michael Chermside mcherm at mcherm.com
Thu Jul 10 16:25:11 CEST 2003


Paul Rudin  writes:
> I haven't been following this thread closely but isn't a regexp the
> obvious way to do this? 

No. The one thing that's QUITE clear is that there are multiple ways
to do this, some of which are more readable than others, but there's
no "one obvious way".

>                         I'd expect it to be faster than your solution
> - particularly on large input (although I haven't actually
> tried). 

Hmm... I doubt it. I'd expect the translate() version to be the
fastest, with multiple string.remove()'s being competative when
the number of different characters to be removed is small. RE's
are NOT renown for their speed when doing simple character
replacement, deletion or insertion on strings. But _I_ haven't 
timed it either, so I'm going to shut up now.

-- Michael Chermside


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/





More information about the Python-list mailing list