I have with my assignment.
class Score:
'A subclass of the object.'
def __init__(self, init):
'Sets the initial score to the object and sets the number of scores
that have contributed to the total to 1.'
self.x = 1
self.init = int(init)
self.total = i
let say i have a file with random letters of A, AB, C, CD, AC, A, D, CD, DD,
C, B, AB, CD, AB
How do i count the occurrence of each individual item.
def occurence(name):
infile = open('bloodtype1.txt', 'r')
lst = infile.read()
infile.close()
print(lst.count('AB')) # 3
print(
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'
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
set