Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python most_common() Function
Next article icon

Python most_common() Function

Last Updated : 17 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

most_common() function is a method provided by the Counter class in Python's collections module. It returns a list of the n most common elements and their counts from a collection, sorted by frequency. Example:

Python
from collections import Counter  a = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']  # create a Counter object counter = Counter(a)  # elements according to the frequency in decreasing order res = counter.most_common() print(res) 

Output
[('apple', 3), ('banana', 2), ('orange', 1)] 

Syntax of most_common()

most_common(n)

Parameters:

  • n (optional): An integer specifying how many of the most common elements to retrieve. Defaults to returning all elements.

Returns: A list of tuples containing the n most common elements and their counts, sorted in descending order by frequency.

Examples of most_common()

Example 1: Finding the Most Common Words in a String

Python
from collections import Counter  s = "Ram and Shyam are friends. Also, Ram and Ghanshyam are college friends. All of them Studies from GeeksforGeeks"  res = Counter(s.split()).most_common(3) print(res) 

Output
[('Ram', 2), ('and', 2), ('are', 2)] 

Explanation: The function splits the text into words and counts how many times each word appears. The three most common words are returned along with their counts.

Example 2: Counting Character Occurrences

Python
from collections import Counter  a = "abracadabra"  # Get the most common character and its count res = Counter(string).most_common(1)  print(res) 

Output
[('a', 5)] 

Explanation: The function counts the occurrence of each character in the string and returns the most common character ('a') along with its frequency (5 times).

Example 3: Identifying Popular Items in a list

Python
from collections import Counter  a = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']  res = Counter(items).most_common(1) print(res) 

Output
[('apple', 3)] 

Explanation: The function counts how many times each item appears in the list and returns the most common item ('apple') with its frequency (3 times).

Related Articles:

  • Python collections Counter
  • Python tutorial

Next Article
Python most_common() Function

O

oceanofknow6flv
Improve
Article Tags :
  • Python
  • Python-Functions
  • Python collections-module
Practice Tags :
  • python
  • python-functions

Similar Reads

    numpy.common_type() function – Python
    numpy.common_type() function return a scalar type which is common to the input arrays. Syntax : numpy.common_type(arrays) Parameters : array1, array2, .... : [ndarrays] Input arrays. Return : [dtype] Return the data type which is common to the input arrays. Code #1 : Python3 # Python program explain
    1 min read
    cmp() function - Python
    cmp() method in Python 2.x compares two integers and returns -1, 0, 1 according to comparison. cmp() does not work in python 3.x. You might want to see list comparison in Python.ExamplePython# Example 1 print(cmp(3, 4)) # Example 2 print(cmp(5, 5)) # Example 3 print(cmp(7, 6)) Output-101ExplanationI
    3 min read
    numpy.find_common_type() function - Python
    numpy.find_common_type() function determine common type following standard coercion rules. Syntax : numpy.find_common_type(array_types, scalar_types) Parameters : array_types : [sequence] A list of dtypes or dtype convertible objects representing arrays. scalar_types : [sequence] A list of dtypes or
    1 min read
    Python Functions
    Python Functions is a block of statements that does a specific task. The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over an
    9 min read
    Python | math.gcd() function
    In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.gcd() function compute the greatest common divisor of 2 numbers mentioned in its arguments. Syntax: math.gcd(x, y) Parameter: x : Non-negative integer whose gcd has to be comp
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences