CBSE Class 11 Computer Science Question 32 of 42

Practice Paper — Question 4

Back to all questions
4
Question

Question 28(a)

Write a program to count the frequency of a given element in a list of numbers.

Solution
my_list = eval(input("Enter the list: "))
c = int(input("Enter the element whose frequency is to be checked: "))
frequency = my_list.count(c)
print("The frequency of", c, "in the list is: ", frequency)
Output
Enter the list: [1, 2, 3, 4, 1, 2, 1, 3, 4, 5, 1]
Enter the element whose frequency is to be checked: 1
The frequency of 1 in the list is:  4
Answer