CBSE Class 11 Informatics Practices
Question 30 of 33
Lists in Python — Question 30
Back to all questions 30
Question WAP to count the frequency of an element in a given list.
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)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
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