Computer Science, asked by avsrikanth015, 3 months ago

WAP to display the frequency of all the elements in a given list cbse 11th

Answers

Answered by Anonymous
1

Answer:

Suppose a list of number is available to you. you are requested to find out the frequency of these elements available in this list using a dictionary.

Dictionary is a data type available in python that can contain unsorted items using keys. The combination of key and value define a dictionary. After the execution of your program, the output should look like this.

Explanation:

where first define the element in the list and the second element defines the frequency of that element in the list.

There are more than one method available to solve this problem, one of the solution is like this

count frequency of element using a dictionary – method -1

# program to find out frequency of each element in a list using dictionary

#   made by           : Sajan

list1 = [1, 2, 3, 4, 5, 6, 7, 34, 2, 2, 2, 4, 6, 7, 7, 8, 9]

freq = {}

for x in list1:

   if x in freq:

       freq[x] += 1

   else:

       freq[x] = 1

Similar questions