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'
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 =
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
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
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
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
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
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
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
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
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
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
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
13 matches
Mail list logo