Deleting characters from a string
Hans Nowak
ivnowa at hvision.nl
Sat Jun 5 17:45:38 EDT 1999
On 5 Jun 99, Hrvoje Niksic wrote:
> string.translate can delete characters from a string, as well as
> translate them. But what if I want *only* to delete them? Currently
> I do this:
>
> dummytable = string.maketrans('', '')
>
> ...
> host = string.translate(host, dummytable, ' "')
> ...
>
> What I would really like to be able to do is write:
>
> host = string.translate(host, None, ' "')
>
> Am I missing a more elegant solution?
Hmm... how about
host = filter(lambda c: not c in ' "', host)
Depends on how much you like, or hate, functional idiom, though. :)
--Hans Nowak (ivnowa at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
More information about the Python-list
mailing list