- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Count Frequency of Highest Frequent Elements in Python

Suppose we have a list of numbers called nums, we have to find the most frequently present element and get the number of occurrences of that element.

So, if the input is like [1,5,8,5,6,3,2,45,7,5,8,7,1,4,6,8,9,10], then the output will be 3 as the number 5 occurs three times.

To solve this, we will follow these steps −

- max:= 0
- length:= size of nums
- for i in range 0 to length-2, do
- count:= 1
- for j in range i+1 to length-1, do
- if nums[i] is same as nums[j], then
- count := count + 1

- if nums[i] is same as nums[j], then
- if max < count, then
- max:= count

- return max

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, nums): max=0 length=len(nums) for i in range(0,length-1): count=1 for j in range(i+1,length): if(nums[i]==nums[j]): count+=1 if(max<count): max=count return max ob = Solution() nums = [1,5,8,5,6,3,2,45,7,5,8,7,1,4,6,8,9,10] print(ob.solve(nums))

## Input

[1,5,8,5,6,3,2,45,7,5,8,7,1,4,6,8,9,10]

## Output

3

- Related Questions & Answers
- Top K Frequent Elements in Python
- Program to find frequency of the most frequent element in Python
- List frequency of elements in Python
- Python – Fractional Frequency of elements in List
- Python - Count the frequency of matrix row length
- Python – Count frequency of sublist in given list
- Python program to count distinct words and count frequency of them
- Find top K frequent elements from a list of tuples in Python
- Count minimum frequency elements in a linked list in C++
- Frequency distribution of elements - JavaScript
- Python – Restrict Elements Frequency in List
- Program to find length of shortest sublist with maximum frequent element with same frequency in Python
- Program to find highest common factor of a list of elements in Python
- Find sum of frequency of given elements in the list in Python
- Delete elements with frequency atmost K in Python

Advertisements