removing characters from a string?
Alex Martelli
alex at magenta.com
Tue Aug 1 03:39:05 EDT 2000
More information about the Python-list mailing list
Tue Aug 1 03:39:05 EDT 2000
- Previous message (by thread): Python license (was RE: Python plug-ins for Adobe Products available)
- Next message (by thread): to close or not to close?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Rikard Bosnjakovic" <bos at hack.org> wrote in message news:3985F5DD.CB1BB073 at hack.org... > jesse at multimediacollective.com wrote: > > > this_string = "jesse at multimediacollective.com" > > """and I wanted to get rid of the @, how would I do that? This > > string.join(string.split(this_string, "@"), "") Or, more directly, string.replace(this_string, '@', ''). However, repeated applications of these idioms are sub-optimal if the goal is to remove all occurrences of all characters in a set, as the original poster suggested. string.translate is optimal for that. identity=string.maketrans('','') # no transformations required string.translate(this_string, identity, '@!$%{}') This will perform exactly the stated request. Alex
- Previous message (by thread): Python license (was RE: Python plug-ins for Adobe Products available)
- Next message (by thread): to close or not to close?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list