[Tutor] How to strip both single and double quotes
Mark Thomas
thomas.s.mark at gmail.com
Wed Oct 5 13:56:13 CEST 2005
On 10/5/05, Dick Moores <rdm at rcblue.com> wrote:
> The text will contain "words" beginning or ending with non-alphabetic
> characters. To strip them off I use string.strip([chars]). My question is
> how to use strip just once to get rid of both kinds of quotes, single and
> double. It seems necessary to do it something like this:
Not sure what you mean by 'words' but how about something like this.
[x.strip('\' \" () * & ^ % $ # < ') for x in word.split()]
Example:
>>> str = 'this has special characters \" \' ()*&^%$# << '
>>> [x.strip('\' \" () * & ^ % $ # < ') for x in str.split()]
['this', 'has', 'special', 'characters', '', '', '', '']
--
_
( ) Mark Thomas ASCII ribbon campaign
X www.theswamp.org - against HTML email
/ \
More information about the Tutor
mailing list