Hey, @Sourav,
We can solve this with the collection module, which refers to count frequencies of all elements in the array link.
import collections #Function to count frequency of each element it returns a dictionary data structure whose keys are array elements and values are their corresponding frequencies {0: 4, 1: 2, 2: 1, 3: 1]
def CountFrequency(arr):
return collections.Counter(arr)
if __name__ == "__main__": #Driver Function
arr = [0, 5, 4, 0, 4, 4, 3, 0, 0, 5, 2, 1, 1, 9]
freq = CountFrequency(arr)
for key, value in freq.iteritems():
print key, " -> ", value
Output:
0-> 4
1->2
2->1
3->1
Hope this will help you.