Re: [Tutor] Looking for Words - Help

2013-10-12 Thread Jackie Canales
from string import punctuation #helper function def strip(text):     'returns text with all punctuation removed'     for symb in punctuation: #import from string         text = text.replace(symb, ' ')              return text #helper function def wordin(s,t):     'does word s occur in text t'    

Re: [Tutor] Looking for Words - Help

2013-10-12 Thread Mark Lawrence
On 12/10/2013 06:18, Jackie Canales wrote: from string import punctuation #helper function I'd be inclined to call this strippunc as strip is use so often. def strip(text): 'returns text with all punctuation removed' for symb in punctuation: #import from string text =

Re: [Tutor] Looking for Words - Help

2013-10-12 Thread Dave Angel
On 12/10/2013 01:18, Jackie Canales wrote: You're still posting in html, not text. I stripped out the markup portion of your message, but you're still left with lots of invisible characters in the following. Your email program is stuffing \xa0 characters in place of every other space, which cuts

Re: [Tutor] Looking for Words - Help

2013-10-12 Thread Alan Gauld
On 12/10/13 06:18, Jackie Canales wrote: for line in lst.splitlines(): if word in line: words = line Notice that you are overwriting words each time you get a match. So the final value of words at the end of the for loop will just be the last line found. All earlier

[Tutor] Looking for Words - Help

2013-10-11 Thread Jackie Canales
Need assistance with a questions in regards to python: 1. function occurs(name, word) which looks for a word in the file with name name. 2. for each occurrence of the word we want to display its context by showing the 5 words (or so) preceding and following the occurrence, e.g. '... a man to

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Dave Angel
On 11/10/2013 01:18, Jackie Canales wrote: Need assistance with a questions in regards to python: 1. function occurs(name, word) which looks for a word in the file with name name. 2. for each occurrence of the word we want to display its context by showing the 5 words (or so) preceding and

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Jackie Canales wrote: Need assistance with a questions in regards to python: 1. function occurs(name, word) which looks for a word in the file with name name. 2. for each occurrence of the word we want to display its context by showing the 5 words (or so) preceding and following the

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Mark Lawrence
On 11/10/2013 06:18, Jackie Canales wrote: for i in range(len(lst)): line = lst[i] Sound advice already from Dave and Peter so I'll just point out for the benefit of newbies that you don't write Python for loops like this, it's. for line in lst: etc Please see

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Alan Gauld
On 11/10/13 06:18, Jackie Canales wrote: Need assistance with a questions in regards to python: 1.function occurs(name, word) which looks for a word in the file with name name. That means you need to define a function called occurs() not lines(). 2. for each occurrence of the word we want to

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Alan Gauld wrote: Use the stripw() function we saw on individual words to make finding hits more accurate No idea what that means but since the assignment suggests it we should assume its correct. My crystal ball says def stripw(word): return word.strip(',.') or somesuch. You have

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Mark Lawrence
On 11/10/2013 15:23, Peter Otten wrote: Alan Gauld wrote: Use the stripw() function we saw on individual words to make finding hits more accurate No idea what that means but since the assignment suggests it we should assume its correct. My crystal ball says def stripw(word): return

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Mark Lawrence wrote: On 11/10/2013 15:23, Peter Otten wrote: Alan Gauld wrote: Use the stripw() function we saw on individual words to make finding hits more accurate No idea what that means but since the assignment suggests it we should assume its correct. My crystal ball says def

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Alan Gauld
On 11/10/13 16:23, Peter Otten wrote: infile = open(name, 'r') lst = infile.readlines() infile.close() You could do that in one line: lst = open(name).readlines() Talking about bad habits -- what you are suggesting here is a step in the wrong direction. with