Count Number Frequency in List

Given a list of integers and a target integer, write a Python program to find the frequency of the target integer in the list.

Example 1:

Input: [1,1,2,2,2,3,4,4,4,4], 2 
Output: 3

Example 2:

Input: [10,10,10,20,20,30,30,30], 10
Output: 3

You can use Python’s built-in count() function for lists.

def count_frequency(nums, target):
    return nums.count(target)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!