remove special characters from line
Irmen de Jong
irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Tue Jul 1 14:01:59 EDT 2003
Chris Rennert wrote:
> Hello all,
>
> If I have a line like this
>
> ²blah blah blah blah blah
>
> I know I could do a slice like this [1:] to pull everything but the special
> character, but what if I have several lines in a file.
> I am not sure how I would detect a special character like that. I would
> just like to pull everything from those lines (and the special character
> always appears as the first character, but not on every line) except for the
> special characters.
What about
>>> special="*!@" # or whatever characters are special
>>> text="*blah blah !! blah blah at blah blah!"
>>> ''.join([c for c in text if c not in special])
'blah blah blah blahblah blah'
--Irmen de Jong
More information about the Python-list
mailing list