Count a Value
You often need to know how many times a specific value appears in a list, such as how many orders have a certain status. Write a function count_occurrences that goes through nums and counts how many elements are equal to target. If the list is empty or the value is not found, return 0.
Примеры
Ввод
[1, 2, 2, 3, 2], 2Вывод
3Ввод
[1, 2, 3], 4Вывод
0Ввод
[], 1Вывод
0Нужно реализовать
def count_occurrences(nums: list[int], target: int) -> int:
Теги
arraylists
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
[1,2,2,3,2], 2Expected
32
Input
[1,2,3], 4Expected
03
Input
[], 1Expected
04
Input
[5,5,5,5], 5Expected
45
Input
[1,2,3,4,5], 3Expected
16
Input
[0,0,1,0], 0Expected
3Focus radio
Paused · SomaFM · Fluid