Programmingempire

The following code shows an example to Count Frequency of Elements in a List in Python. At first, we create a list containing duplicate elements. In order to find the frequency of each element, we need to find how many times an element appears in the list. Therefore, we create an empty list first. Further, we find the ith element in the original list in the new list. If the element is not there in the new list, we append it. Hence, in the new list, we get all the unique elements from the original list. Further, we start another loop that iterates over all elements in the new list. Here we create a counter for each element and assign it a value of 0. After that, we increment the counter for every occurrence of a particular element in the original list. Hence, we get the count of each element in the original list.

mylist=[12,1,3,54,12,12,3,3,3,5,6,3,54,3,2,54]
print('list elements: ')
for i in range(len(mylist)):
   print(mylist[i])
   

print('Counting element frequencies the list...')
list1=[]
for i in range(len(mylist)):
   f=False
   for j in range(len(list1)):
      if list1[j]==mylist[i]:
        f=True
   if f==False:
     list1.append(mylist[i])
         
for i in range(len(list1)):
   counter=0
   for j in range(len(mylist)):
      if list1[i]==mylist[j]:
        counter+=1
   print(str(list1[i])+' appears '+str(counter)+' times')

Output

The Output of the Program to Count Frequency of Elements in a List in Python
The Output of the Program to Count Frequency of Elements in a List in Python

Further Reading

Deep Learning Tutorial

Text Summarization Techniques

How to Implement Inheritance in Python

Find Prime Numbers in Given Range in Python

Running Instructions in an Interactive Interpreter in Python

Deep Learning Practice Exercise

Python Practice Exercise

Deep Learning Methods for Object Detection

Understanding YOLO Algorithm

What is Image Segmentation?

ImageNet and its Applications

Image Contrast Enhancement using Histogram Equalization

Transfer Learning and its Applications

Examples of OpenCV Library in Python

Examples of Tuples in Python

Python List Practice Exercise

Understanding Blockchain Concepts

Edge Detection Using OpenCV

Predicting with Time Series

Example of Multi-layer Perceptron Classifier in Python

Measuring Performance of Classification using Confusion Matrix

Artificial Neural Network (ANN) Model using Scikit-Learn

Popular Machine Learning Algorithms for Prediction

Long Short Term Memory – An Artificial Recurrent Neural Network Architecture

Python Project Ideas for Undergraduate Students

Creating Basic Charts using Plotly

Visualizing Regression Models with lmplot() and residplot() in Seaborn

Data Visualization with Pandas

A Brief Introduction of Pandas Library in Python

A Brief Tutorial on NumPy in Python

programmingempire