List challenge why is mine wrong

Beginner here,

The solution provided returns the value True and is correct
My solution also provides the value True however when I hit check answer it flags it up and says the answer should have been False.

1 Like

Hey there @archtronics and welcome to the forums!! :grinning:

What variables are being used to test the two functions?
Seems odd that the solution would answer True and say yours should be False.
Could you post a link to the lesson?


Some times two different functions will produce identical results under the right circumstances, but under different circumstances they may vary.

Take a look at how you are defining your variables compared to how the solution does:

item_count = lst.count(item)
n_count = lst.count(n)

if item_count > n_count:

What exactly are you comparing here?

Your first variable is indeed the number of times that the lst contains item, but if you look at the instructions, it says it want you to see if item appears in the list more than n times. This would refer to n as an integer value (say 6 for example) and you are supposed to see if item appears that many times.

Hint if you are still stuck

Since .count() return the number of times an object appears in a string or list, than n_count is now equal to the number of times the integer 6 was found in lst, instead of the integer value provided 6.

Because of this the function now solves for:

Is the number of times item appears in lst greater than the number of times n apears in lst.


An added something to consider

.count() can be used on both lists and strings, however even though you can count for an integer, or a string, or a boolean, or any other value type I know of within a list, you can only test for a string value within a string:

>>> string = "H1 there!"
>>> print(string.count(1))
TypeError: must be str, not int

4 Likes