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


>>>

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Traceback (most recent call last):
    File "C:\Users\CDA\Desktop\aa", line 2, in
    for i in lst:
    TypeError: 'int' object is not iterable

    ReplyDelete
  2. Enter a list :-6

    Traceback (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

    ReplyDelete
    Replies
    1. You are entering integer but you have to input a lst of number.

      Delete
    2. Add a comma after the digit

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post