Beginner is here! I am writing simple code to calculate how many times an item is displayed in a list (e.g. count([1, 3, 1, 4, 1, 5], 1)returns 3).
This is what I originally had:
def count(sequence, item):
s = 0
for i in sequence:
if int(i) == int(item):
s += 1
return s
Every time I sent this code, I received
"invalid literal for int () with base 10:"
Since then, I realized that the correct code is:
def count(sequence, item):
s = 0
for i in sequence:
if **i == item**:
s += 1
return s
However, I'm just wondering what this error expression means. Why can't I just leave in int()?
source
share