CBSE Class 11 Informatics Practices Question 67 of 80

Lists in Python — Question 30

Back to all questions
30
Question

Question 25

WAP to count the frequency of an element in a given list.

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