Re: [Tutor] Count Help

2013-10-25 Thread Konrad Korżel
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

Re: [Tutor] Count Help

2013-10-24 Thread Dave Angel
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