[Tutor] How to strip both single and double quotes

Dick Moores rdm at rcblue.com
Wed Oct 5 11:43:47 CEST 2005


I'm writing a script that takes any text and outputs to a file a list of 
duples (k, word) where k is the number of occurrences of word in the text.

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:

# L is the original list of "words" in the text.
newL = []
for word in L:
     word = lower(word)
     newWord = word.strip(".,!?;:&*'=-></#@)(")
     newWord2 = newWord.strip('.,!?;:&*"=-></#@)(')
     word = newWord2
     newL.append(word)

But is it? Have I missed something?

Thanks,

Dick Moores



More information about the Tutor mailing list