# Why is "Count" not working

**URL:** <https://discuss.python.org/t/why-is-count-not-working/8157>\
**Category:** Python Help\
**Created:** [April 9, 2021, 8:50pm UTC](https://discuss.python.org/t/why-is-count-not-working/8157 "2021-04-09T20:50:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geo4tune](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@Geo4tune](https://discuss.python.org/u/Geo4tune)\
**Post date:** [April 9, 2021, 8:50pm UTC](https://discuss.python.org/t/why-is-count-not-working/8157/1 "2021-04-09T20:50:38Z")

</div>

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=’,’)  
next(csv\_reader)  
for lines in csv\_reader:  
newlist.append(lines)

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

---

<div class="post-metadata">

**Author:** ![BowlOfRed](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bowlofred/32/3379_2.png) [@BowlOfRed](https://discuss.python.org/u/BowlOfRed)\
**Post date:** [April 9, 2021, 9:50pm UTC](https://discuss.python.org/t/why-is-count-not-working/8157/2 "2021-04-09T21:50:06Z")

</div>

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?

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Geo4tune](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@Geo4tune](https://discuss.python.org/u/Geo4tune)\
**Post date:** [April 9, 2021, 10:21pm UTC](https://discuss.python.org/t/why-is-count-not-working/8157/3 "2021-04-09T22:21:16Z")

</div>

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.
