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
PostgreSQLv16

Taispeánfar toradh do chóid anseo

Visible tests
1
Input
[1,2,2,3,2], 2
Expected3
2
Input
[1,2,3], 4
Expected0
3
Input
[], 1
Expected0
4
Input
[5,5,5,5], 5
Expected4
5
Input
[1,2,3,4,5], 3
Expected1
6
Input
[0,0,1,0], 0
Expected3
Focus radio
Paused · SomaFM · Fluid