Quick question concerning a function including a list


#1

On
https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-lists/lessons/python-functions-lists-cc/exercises/more-than-n

My original function was

def more_than_n(lst, item, n):
if item > lst.count(n):
return True
else: return False

it returned correctly until it hit an equal int.
at that time, it returned True instead of False.
Why?


#2

Hi @jacobjenson424642936,

The instructions include this …

The function should return True if item appears in the list more than n times.

However, here you are counting the occurrences of n in lst and comparing the result to item

  if item > lst.count(n):

Instead, you need to count the occurrences of item in lst and compare the result to n.