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
What will be the output of the following code? Also, give the minimum and maximum values of the variable x.
import random List = ["Delhi", "Mumbai", "Chennai", "Kolkata"] for y in range(4): x = random.randint(1, 3) print(List[x], end = "#")
Explain the given built-in string functions and provide the syntax and example of each.
(a) replace()
(b) title()
(c) partition()
Write a program to check if the smallest element of a tuple is present at the middle position of the tuple.
What are the characteristics of Dictionary?