Why is "Count" not working

I am not a programmer (obviously), but I can’t get the result I’m looking for, which is how many times is the number 4 appear in the list. BC491 is a comma delimited file. Thank you.

import csv
newlist =

with open(“bc491.csv”, “r”) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=’,’)
for lines in csv_reader:

print("This is the data: ", newlist)
a = newlist.count(4)
print("How many 4s?: ", a)

You don’t show the data, so I’m assuming that you have multiple lines of comma-separated fields. From csv.reader:

Each row read from the csv file is returned as a list of strings. No automatic data type conversion is performed unless the QUOTE_NONNUMERIC format option is specified (in which case unquoted fields are transformed into floats).

The above means that newlist will be lists of lists of strings, and the int 4 can never be found as an element within. You might want to be looking instead for the string "4", but only in each of the lines itself.

Maybe something like this instead?

import csv

with open("bc491.csv", "r") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=",")
    newlist = list(csv_reader)[1:]

print("This is the data: ", newlist)
a = sum(x.count("4") for x in newlist)
print("How many 4s?: ", a)

Thank you very sir!!! Your solution works. Now I’ll have to dissect it to see what you’ve done. Your assumption was obviously correct about the type of file I had. I just wasn’t sure how to show it. Regardless, I had hoped that someone would see the mistake in my code without the data - and you did.