Eat this one
Steve Purcell
stephen_purcell at yahoo.com
Tue Mar 27 11:14:23 EST 2001
Rikard Bosnjakovic wrote:
> I feel ashamed to show the code, but I didn't find any other solution :)
>
> What way would be better and _faster_ to wipe out the five chars from
> the list?
Here is a nice readable way:
>>> import string
>>> s = 'here is < some > text with& nasty characters'
>>> for badchar in "<>&\n":
... s = string.replace(s,badchar,'')
...
>>> s
'here is some text with nasty characters'
And using regular expressions:
>>> import re
>>> s2 = re.sub('[<>&\n]', '', s)
>>> s2
'here is some text with nasty characters'
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo
More information about the Python-list
mailing list