Of course, you should read all the ratings, which in this case also means reading the entire file. You can use the csv module to easily read comma separated value files:
import csv my_reader = csv.reader(open('my_file.csv')) ctr = 0 for record in my_reader: if record[1] == 'A': ctr += 1 print(ctr)
This is pretty fast, and I could not have done better with the Counter method:
from collections import Counter grades = [rec[1] for rec in my_reader]
Last but not least, lists have a count method:
from collections import Counter grades = [rec[1] for rec in my_reader] result = grades.count('A') print(result)
source share