KnowledgeBoat Logo

Computer Science

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

Python

Python List Manipulation

11 Likes

Answer

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

Answered By

3 Likes


Related Questions