SPOILER: CONTAINS ANSWER
The code that tests our function appears to reference check the sequence given after we have potentially messed with it.
My code provides the actual correct answer, but the reference check believes the answer should be 0 since all of the counted items have been removed.
My code below directly removes the item from the sequence while counting how many it removes:
def count(sequence, item): count = 0 while sequence.`__contains__`(item): sequence.remove(item) count += 1 return count
This returns an error for every sequence except for the first two, saying that the actual answer should be ‘0’
The answer code they provide doesn’t directly mess with the code:
def count(sequence, item):
count = 0
for i in sequence:
if i == item:
count += 1