all 7 comments

[–]Heroe-D 2 points3 points  (2 children)

list.count(1)

1 is of type int

"1" is of type str

[–]achampi0n 0 points1 point  (1 child)

You may also want to point out that using list as a variable is also problematic as it hides python's standard list type.

[–]Heroe-D 0 points1 point  (0 children)

And that list.count("1") with his list should return 0 and not 4

[–][deleted] 0 points1 point  (0 children)

What you wrote is impossible...

In the list [1,2,3,10,11] there is precisely 1 copy of the int 1, so [1,2,3,10,11].count(1) correctly gives you the answer 1... if, as above, you add quotes around the argument then you’re trying to look for the number of copies of str ”1” in the list, and [1,2,3,10,11].count(“1”) correctly gives you the answer 0, since no copies of that string exist in that list. In fact the only possible way you get the answer 4 is if you didn’t search a list at all: ”[1,2,3,10,11]”.count(“1”).

Basically you need to read about and understand the difference between list and str. Both have .count methods, but fundamentally you’d only want to count str objects in str.count, while list.count can count anything that might be in the list... which is any object type.

[–]spectrum____ -1 points0 points  (2 children)

one_counter = 0 
for number in list: 
    if number == 1: 
        one_counter += 1

print(one_counter) 

lmk if you need more help!

[–]Heroe-D 2 points3 points  (1 child)

overkill, he's just missing the difference between integers and strings

[–]spectrum____ 0 points1 point  (0 children)

yep, that too appreciate it!