It's better to use the "with open" statement to open the file and then
process it line by line with occurrence counter, like:
def occurence(pathToFile, substring):
substringCount = 0
with open(pathToFile, 'r') as src:
for line in src:
substringCount += line.count(substr
On 23/10/2013 22:12, Jackie Canales wrote:
> 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()
rea