Program to Find Frequency of each element in a array in Python

Program to Find Frequency of each element in a array in Python. This program contains For loop, Array initialisation, Input and Print commands. This program is for Beginners, class 11, 12 and B Tech computer science students.

Program to Find Frequency of each element in a array in Python

What is an Array ?

An array is defined as a collection of items that are stored at contiguous memory locations.

What is Frequency ?

Here the frequency of elements refers to the n.o of times a element is repeated.

Source code:

#Enter the length of Array
n= int(input("Enter the length of Array"))
#Intialising a array
a=[None]*n
#running a for loop for the enter of array
for i in range (0,n):
    m= int(input( " Enter the content of Array")) 
    a[i]=m
#for checking the n.o of times a number occuring in an array
for i in range (0,n):
    #print (a[i])
    count=0
    
    for j in range (0,n):
        if a[i]==a[j]:
            count= count+1
    print(a[i]," number is  occuring  freqency in this much time",count)

Explanation of Source code :

step 1:Enter the length of Array
n= int(input(“Enter the length of Array”))
step 2:Intialising a array
a=[None]*n
step 3:running a for loop for the enter of array
for i in range (0,n):
m= int(input( ” Enter the content of Array”))
a[i]=m
step 4:for checking the n.o of times a number occuring in an array
for i in range (0,n):
step 5:for printing
print (a[i])
count=0
for j in range (0,n):
if a[i]==a[j]:
count= count+1
print(a[i],” number is occuring freqency in this much time”,count)

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:\csstudy\source code file 2\Python program to find the frequency of each element in the array.py 
Enter the length of Array9
 Enter the content of Array1
 Enter the content of Array1
 Enter the content of Array1
 Enter the content of Array2
 Enter the content of Array3
 Enter the content of Array2
 Enter the content of Array3
 Enter the content of Array2
 Enter the content of Array2
1  number is  occuring  freqency in this much time 3
1  number is  occuring  freqency in this much time 3
1  number is  occuring  freqency in this much time 3
2  number is  occuring  freqency in this much time 4
3  number is  occuring  freqency in this much time 2
2  number is  occuring  freqency in this much time 4
3  number is  occuring  freqency in this much time 2
2  number is  occuring  freqency in this much time 4
2  number is  occuring  freqency in this much time 4
>>> 

Output Explanation:

The output asks for the input of length size of Array and contents of Array and then prints after calculating the numbers of times the terms is called.

Enter the length of Array9
Enter the content of Array1
Enter the content of Array1
Enter the content of Array1
Enter the content of Array2
Enter the content of Array3
Enter the content of Array2
Enter the content of Array3
Enter the content of Array2
Enter the content of Array2
1 number is occuring freqency in this much time 3
1 number is occuring freqency in this much time 3
1 number is occuring freqency in this much time 3
2 number is occuring freqency in this much time 4
3 number is occuring freqency in this much time 2
2 number is occuring freqency in this much time 4
3 number is occuring freqency in this much time 2
2 number is occuring freqency in this much time 4
2 number is occuring freqency in this much time 4

Conclusion:

This program is running fine.

Thank you for learning, reading and downloading Program to Find Frequency of each element in a array in Python.This program contains for loop, array initialisation, input and print commands. This program is for Beginners, class 11, 12 and B Tech computer science students. For more programs clicks the links below-
Python Programs Archives – CS Study
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

Your email address will not be published.