Re: [Tutor] can this be done easerly

2010-08-30 Thread ALAN GAULD
>test = word.strip('!?,.--') >s2.append(test) >return s2 > >if __name__ == '__main__': >import doctest >doctest.testmod() > >But now the doctest failes with this : > >Expected: >['she', 'tried', 'to', 'curtsey', 'as

Re: [Tutor] can this be done easerly

2010-08-30 Thread ALAN GAULD
> 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 str

Re: [Tutor] can this be done easerly

2010-08-30 Thread Steven D'Aprano
On Mon, 30 Aug 2010 07:44:06 pm Roelof Wobben wrote: > Hello, > > > > For a exerise I made this one :" > > > > import string > > def extract_words(s): [...] > But now I wonder if this can be done more easerly ? def extract_words(s):     """     >>> extract_words('Now is the time!  "Now", is the

Re: [Tutor] can this be done easerly

2010-08-30 Thread Alan Gauld
"Roelof Wobben" wrote import string I know your tutorial uses the string module but you really should get out of that habit. It will not work in the newer versions of Python and is less efficient that using the builtin methods. And invariably requires more typing! :-) def extract_words(s):

Re: [Tutor] can this be done easerly

2010-08-30 Thread Roelof Wobben
> Subject: Re: [Tutor] can this be done easerly > From: evert@gmail.com > Date: Mon, 30 Aug 2010 12:04:08 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > > > For a exerise I made this one :" > > > > import string > > def extract_

Re: [Tutor] can this be done easerly

2010-08-30 Thread Evert Rol
> For a exerise I made this one :" > > import string > def extract_words(s): > """ > >>> extract_words('Now is the time! "Now", is the time? Yes, now.') > ['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now'] > >>> extract_words('she tried to curtsey as she

[Tutor] can this be done easerly

2010-08-30 Thread Roelof Wobben
Hello, For a exerise I made this one :" import string def extract_words(s): """ >>> extract_words('Now is the time! "Now", is the time? Yes, now.') ['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now'] >>> extract_words('she tried to curtsey as she