76. Python Program to Display Frequency of each Element from Array.
How does this program work?
- This program is used to find frequency of each element in given array using Python.
- In this program we need to count the occurrence of each element present in the array.
- Declare two arrays one will be store elements, and another(fr) will be store the frequencies of elements present in an array.
- And variable check will initialize with -1, because it helps us to avoid counting the same element again in the given array.
Here is the code
import collections
a = list()
number = int(input( "Enter the number of elements you want: "))
print ('Enter numbers in array: ')
for i in range(int(number)):
n = input( "number : ")
a.append (int(n))
fre = collections.Counter(a)
print("Array elements :")
print (a)
print ("Frequency table of an array elements")
for key,val in fre.items():
print(key, "-> ",val)