[Tutor] Looking for Words - Help
Jackie Canales
jackiexxduh at yahoo.com
Sat Oct 12 07:18:56 CEST 2013
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'
#s in t
t = strip(t)
return s in t.split()
def lines(name, word):
'print all lines of name in which word occurs'
infile = open(name, 'r')
lst = infile.read()
infile.close()
for line in lst.splitlines():
if word in line:
words = line
for index, word in enumerate(words):
print(words)
LINK TO CODE:http://codetidy.com/6926/
Thank you for the help so far! I figured out how to split the file in order to only out all the lines that have the word river in it. I tried reading up on enumerate but I am still having trouble understanding it. The code above just repeats this line in the middle of the page about 20 times.
probably essentially dam the widest river in the world.
LINK: http://imgur.com/7pZvfzA
I tried understanding the feedback given to me the above is what i got so far if you could please help me with the enumerate.
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131011/106023aa/attachment-0001.html>
More information about the Tutor
mailing list