# Finding the frequency of element Frequency of elements in an array using Python ## Frequency of elements in an array using Python

In this paragraph, we will learn how to code in Python. Here we have an array of elements to count the frequency or occurrence of its each element entered by the user. One of the approaches to resolve this problem is to maintain one array to store the counts of each element of the array then iterate loop through the array and count the frequency of each element and store it in another array.

For example:
Enter the size of array: 5
Enter the elements:
2  3   31  2  3
The occurrence of 2 is 2
The occurrence of 3 is 2
The occurrence of 31 is 1 ## Working required for finding the frequency of list using Python

STEP 1: Declare and Initialize an array.

STEP 2: Take the input in the array.

STEP 3: Make another array to store the frequency of elements.

STEP 4: Than Traverse the input array and update the count of the elements in the frequency array.

STEP 5: Now print the frequency array which displays the frequency of all the elements of the array

## Finding the frequency of elements in an array using python

```n=int(input("ENTER ARRAY SIZE "))

arr=[]

print("Enter the array elements")

for i in range(n):

arr.append(int(input()))

x=list(dict.fromkeys(arr))

for i in x:

print("\n {} occurs {} time(s)".format(i,arr.count(i)))```
```Output#Test case 1
Enter ARRAY SIZE 6
Enter the array elements
4
33
199
9
33
199

4 occures 1 time(s)
33 occures 2 time(s)
199 occures 2 time(s)
9 occures 1 time(s)#Test case 2Enter ARRAY SIZE 6Enter the array elements 4 399 354 occures 1 time(s) 3 occures 2 time(s) 9 occures 2 time(s) 5 occures 1 time(s)
```

### One comment on “Finding the frequency of element Frequency of elements in an array using Python”

• hrushikesh

list= [1,2,3,12,3,4,55,5,5,6,7,2,3,4,4,5,6,7,7,8]
freq = {}
for value in list:
if value in freq:
val = freq[value]
val += 1
freq[value] = val
else:
freq[value] = 1

for value in freq:
print(‘The occurrence of’,value,’is’,freq[value]) 6