Ive written a function that counts how often a number smaller than my compared_number is in a list. But when executing it. I get the error in the title. Heres my function:
def count_smaller(input_list: List[int], compared_number: int) -> int:
for l in List:
if compared_number<0:
break
elif compared_number<List[l]:
count+=1
return count
List
is an object defining a type, not your actual list object. You can read more about type hinting in the documentation
As you iterate over the list with for l in input_list
, use the element l
of the list directly in your comparison :
def count_smaller(input_list: List[int], compared_number: int) -> int:
for l in input_list:
if compared_number<0:
break
elif compared_number<l:
count+=1
return count