Q. Write a Program to count the frequency of an element in a given list.
Answer =
lst = eval(input("Enter a list :-")) for i in lst : feq = lst.count(i) print("Frequency of ",i,"=",feq)
Output :-
Enter a list :-[1,5,3,9,4,2,0,8,6,9,4,0,3,1,7,6,3]
Frequency of 1 = 2
Frequency of 5 = 1
Frequency of 3 = 3
Frequency of 9 = 2
Frequency of 4 = 2
Frequency of 2 = 1
Frequency of 0 = 2
Frequency of 8 = 1
Frequency of 6 = 2
Frequency of 9 = 2
Frequency of 4 = 2
Frequency of 0 = 2
Frequency of 3 = 3
Frequency of 1 = 2
Frequency of 7 = 1
Frequency of 6 = 2
Frequency of 3 = 3
>>>
Traceback (most recent call last):
ReplyDeleteFile "C:\Users\CDA\Desktop\aa", line 2, in
for i in lst:
TypeError: 'int' object is not iterable
Enter a list :-6
ReplyDeleteTraceback (most recent call last):
File "C:\Users\CDA\Desktop\aa", line 1, in
lst = eval(input("Enter a list :-"))
TypeError: eval() arg 1 must be a string or code object
You are entering integer but you have to input a lst of number.
DeleteAdd a comma after the digit
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )