0 out of 464 challenges solved
Write a Python function `frequency(lst, num)` that takes a list of integers `lst` and an integer `num` as input and returns the number of times `num` appears in `lst`. #### Example Usage ```python [main.nopy] print(frequency([1, 2, 3, 4, 2, 2], 2)) # Output: 3 print(frequency([5, 5, 5, 5], 5)) # Output: 4 print(frequency([1, 2, 3], 4)) # Output: 0 ``` #### Constraints - The input list can contain any integers, including negative numbers. - The function should return `0` if the number does not appear in the list.
def frequency(lst, num):
"""
Count the number of occurrences of `num` in the list `lst`.
Args:
lst (list): A list of integers.
num (int): The integer to count in the list.
Returns:
int: The count of occurrences of `num` in `lst`.
"""
# Initialize a counter variable
count = 0
# Iterate through the list and count occurrences of `num`
# Placeholder for the solution
return count