[Tutor] can this be done easerly

ALAN GAULD alan.gauld at btinternet.com
Mon Aug 30 19:01:04 CEST 2010

> I tried your suggestion with strip and it looks like this :
> import string

You don't need this now

> def extract_words(s):
>    word= ""

You dont need this

>     s2=[]
>     s = string.lower(s)
>     s = s.replace( "--", " ")

You probably don't need this either - just add '-' to the strip set.

>     s = s.split()
>     for word in s:

And you could combine those to

for word in s.split():

>         test = word 
>         test = word.strip('!?,.')

You don't need test, just use

word = word.strip('!?",.-')  #added " and - to your set...

>         s2.append(test)
>     return s2
> It works well only I can't get it to work the strip with ". 
> I always get a EOF error message. I tried it with 
> word.strip('!?,.") and with word.strip('!?,./"'') but no go.

It looks like you are mixing quote styles.
Notice how I included the " in the strip() above... 
See if that works for you.

Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100830/c975395a/attachment.html>

More information about the Tutor mailing list