Seedha content par jao
ЁЯдЦ Python Hindi Bot
Namaste! Main Python Hindi Bot hoon ЁЯРН
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education
Python programming tutorial in Hindi banner Python code learning illustration Hindi Python student coding illustration Python data code pattern background

Python Tutorial in HindiiLearn Python Programming for Free

Learn Python from Beginner to Advanced in simple Hindi.

print("Namaste Python!")
# Variable banana
naam = "Ankit"
umar = 25
 
for i in range(3):
  print("Sikho!")
 
# Output:
Sikho! Sikho! Sikho!

Why Students Learn Here

ЁЯУЪ

Structured Tutorials

Beginner se Advanced tak step-by-step organized lessons.

ЁЯТ╗

Practical Code

Real examples aur hands-on code jo actually samajh aaye.

ЁЯза

Python + AI Path

Ek clear roadmap jo Python se AI tak le jaata hai.

ЁЯЪА

Projects & Career

Portfolio-ready projects aur interview preparation.

Ye Kaise Kaam Karta Hai

Hindi mein Python, AI aur Data Skills seekhne ka sabse simple tareeka.

ЁЯУШ

Seekhein

Beginner se Advanced tak, best curated tutorials aur guides Hindi mein.

ЁЯТ╗

Practice Karein

Real code examples aur mini-projects ke through hands-on practice karein.

ЁЯТм

Judein

WhatsApp community se judkar apne doubts clear karein, akele nahi seekhenge.

Python to AI Learning Roadmap

Step-by-step learning path from Python basics to AI, Data Science and career-ready projects.

1
ЁЯРН

Python Basics

Introduction, Variables, Data Types, Operators, Input & Output, Conditions, Loops, Functions

Start Python →
2
ЁЯТ╗

Python Intermediate

Lists, Tuples, Sets, Dictionaries, Strings, Functions, Modules, File Handling, Exception Handling

Continue Python →
3
⚙️

Advanced Python

OOP, Iterators, Generators, Decorators, Regular Expressions, APIs, Automation, Virtual Environments

Learn Advanced Python →
4
ЁЯЧД️

SQL & Databases

SQL Basics, MySQL, SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, Database Projects

Learn SQL →
5
ЁЯУК

Data Analytics

NumPy, Pandas, Data Cleaning, Data Visualization, Matplotlib, Exploratory Data Analysis

Learn Data Analytics →
6
ЁЯдЦ

Machine Learning

ML Basics, Supervised & Unsupervised Learning, Regression, Classification, Model Evaluation, Scikit-learn

Learn Machine Learning →
7
ЁЯза

Artificial Intelligence

AI Fundamentals, Generative AI, AI Tools, Prompt Engineering, LLM Concepts, AI Automation

Explore AI →
8
ЁЯЪА

Projects & Career

Python Projects, AI Projects, Data Projects, Portfolio, GitHub, Interview Preparation, Career Roadmap

Build Your Career →

Python Counter Explained in Hindi ЁЯФе | collections.Counter Tutorial | Python Hindi

Python Counter Explained in Hindi - collections.Counter Tutorial

Python Counter

Python рдоें рдЕрдХ्рд╕рд░ рд╣рдоें рдпрд╣ рдЬाрдирдиा рд╣ोрддा рд╣ै рдХि рдХिрд╕ी list рдпा string рдоें рдХोрдИ value рдХिрддрдиी рдмाрд░ рдЖрдИ рд╣ै — рдЬैрд╕े рдХिрд╕ी word рдоें рдХौрди рд╕ा letter рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдпा, рдпा рдХिрд╕ी survey рдоें рдХिрд╕ option рдХो рд╕рдмрд╕े рдЬ्рдпाрджा рд╡ोрдЯ рдоिрд▓े। рдЗрд╕рдХे рд▓िрдП Python рдХा collections.Counter рдПрдХ рдмрд╣ुрдд рдЙрдкрдпोрдЧी tool рд╣ै।

рдЕрдЧрд░ рдЖрдкрдиे рдЕрднी Python Dictionary in Hindi рдирд╣ीं рдкрдв़ा рд╣ै, рддो рдкрд╣рд▓े рд╡ो article рдкрдв़рдиा рдЙрдкрдпोрдЧी рд░рд╣ेрдЧा, рдХ्рдпोंрдХि Counter рдЕрд╕рд▓ рдоें dictionary рдХा рд╣ी рдПрдХ special version рд╣ै। Examples рдЦुрдж run рдХрд░рдиे рдХे рд▓िрдП рд╣рдоाрд░ा Online Python Editor & Compiler use рдХрд░ рд╕рдХрддे рд╣ैं।

ЁЯОе Video рдоें рдкूрд░ा Topic рд╕рдордЭें

Python Counter рдХ्рдпा рд╣ै?

Counter Python рдХे collections module рдХा рдПрдХ tool рд╣ै, рдЬो рдХिрд╕ी iterable (list, string, рдЖрджि) рдХे рд╣рд░ element рдХी frequency (рдХिрддрдиी рдмाрд░ рдЖрдпा) count рдХрд░рдХे рдПрдХ dictionary рдЬैрд╕ा object рдмрдиा рджेрддा рд╣ै।

рд╕рд░рд▓ рднाрд╖ा рдоें — Counter рд╣рд░ value рдХो рдЧिрдирдХрд░ рдмрддा рджेрддा рд╣ै рдХि рд╡рд╣ рдХिрддрдиी рдмाрд░ рдЖрдИ рд╣ै।
Example
from collections import Counter fruits = ["apple", "banana", "apple", "mango", "banana", "apple"] count = Counter(fruits) print(count)

Output:

Counter({'apple': 3, 'banana': 2, 'mango': 1})
Try it Yourself »

Counter рдХो Import рдХैрд╕े рдХрд░ें?

Counter Python рдХा built-in keyword рдирд╣ीं рд╣ै — рдЗрд╕े рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиे рд╕े рдкрд╣рд▓े collections module рд╕े import рдХрд░рдиा рдЬрд░ूрд░ी рд╣ै।

Syntax
from collections import Counter
Note: рдЕрдЧрд░ рдмिрдиा import рдХिрдП Counter рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиे рдХी рдХोрд╢िрд╢ рдХрд░ेंрдЧे, рддो Python NameError рджेрдЧा।

List рдоें Values рдХी Frequency рдиिрдХाрд▓рдиा

Example
from collections import Counter numbers = [1, 2, 2, 3, 3, 3, 4] count = Counter(numbers) print(count)

Output:

Counter({3: 3, 2: 2, 1: 1, 4: 1})

рдпрд╣ाँ рд╕ाрдл рджिрдЦ рд░рд╣ा рд╣ै рдХि 3 рд╕рдмрд╕े рдЬ्рдпाрджा (3 рдмाрд░), рдФрд░ рдмाрдХी numbers рдХрдо рдмाрд░ рдЖрдП рд╣ैं।

Try it Yourself »

String рдоें Characters Count рдХрд░рдиा

Counter рд╕िрд░्рдл list рд╣ी рдирд╣ीं, рдХिрд╕ी string рдХे рд╣рд░ character рдХी frequency рднी рдиिрдХाрд▓ рд╕рдХрддा рд╣ै, рдХ्рдпोंрдХि string рднी рдПрдХ iterable рд╣ै।

Example
from collections import Counter word = "programming" letter_count = Counter(word) print(letter_count)

Output:

Counter({'r': 2, 'g': 2, 'm': 2, 'p': 1, 'o': 1, 'a': 1, 'i': 1, 'n': 1})
Try it Yourself »

рдХिрд╕ी Specific Item рдХा Count рдиिрдХाрд▓рдиा

рдХिрд╕ी рдПрдХ particular value рдХा count рдиिрдХाрд▓рдиे рдХे рд▓िрдП рдЙрд╕े dictionary рдХी рддрд░рд╣ key рд╕े access рдХिрдпा рдЬाрддा рд╣ै।

Example
from collections import Counter fruits = ["apple", "banana", "apple", "mango", "apple"] count = Counter(fruits) print(count["apple"]) print(count["mango"])

Output:

3 1
Try it Yourself »
Note: рдЕрдЧрд░ рдХोрдИ value Counter рдоें рдоौрдЬूрдж рд╣ी рди рд╣ो, рддो normal dictionary рдХी рддрд░рд╣ KeyError рдЖрдиे рдХी рдмрдЬाрдп Counter 0 return рдХрд░рддा рд╣ै।
Example
from collections import Counter fruits = Counter(["apple", "banana"]) print(fruits["grapes"])

Output:

0
Try it Yourself »

most_common() рдХा Basic рдЙрдкрдпोрдЧ

most_common() рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдиे рд╡ाрд▓े elements рдХो рдЙрдирдХे count рдХे рд╕ाрде return рдХрд░рддा рд╣ै।

Example — рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдиे рд╡ाрд▓ा 1 element
from collections import Counter word = "programming" letter_count = Counter(word) print(letter_count.most_common(1))

Output:

[('r', 2)]
Try it Yourself »
Example — рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдиे рд╡ाрд▓े 2 elements
from collections import Counter word = "programming" letter_count = Counter(word) print(letter_count.most_common(2))

Output:

[('r', 2), ('g', 2)]

рдЕрдЧрд░ most_common() рдоें рдХोрдИ number рди рджिрдпा рдЬाрдП, рддो рдпрд╣ рд╕ाрд░े elements рдХो рдЙрдирдХे count рдХे рд╣िрд╕ाрдм рд╕े рд╕рдмрд╕े рдЬ्рдпाрджा рд╕े рд╕рдмрд╕े рдХрдо рдХ्рд░рдо рдоें return рдХрд░рддा рд╣ै।

Try it Yourself »

Practical Voting Example

Example
from collections import Counter votes = ["Candidate A", "Candidate B", "Candidate A", "Candidate C", "Candidate A", "Candidate B", "Candidate A"] result = Counter(votes) print("All Votes:", result) print("Winner:", result.most_common(1))

Output:

All Votes: Counter({'Candidate A': 4, 'Candidate B': 2, 'Candidate C': 1}) Winner: [('Candidate A', 4)]

рдпрд╣ Counter рдХा рдПрдХ рдмрд╣ुрдд practical real-world рдЗрд╕्рддेрдоाрд▓ рд╣ै — рдмिрдиा рдХिрд╕ी manual loop рдХे, winner рддुрд░ंрдд рдкрддा рдЪрд▓ рдЧрдпा।

Try it Yourself »

Student/Data Example

Example — Grades Analysis
from collections import Counter grades = ["A", "B", "A", "C", "B", "A", "D", "B"] grade_count = Counter(grades) print("Grade Distribution:", grade_count) print("Most Common Grade:", grade_count.most_common(1)) print("Students with 'A':", grade_count["A"])

Output:

Grade Distribution: Counter({'A': 3, 'B': 3, 'C': 1, 'D': 1}) Most Common Grade: [('A', 3)] Students with 'A': 3
Try it Yourself »

Counter рдФрд░ count() рдХा Basic Difference

List рдоें рдПрдХ built-in count() method рднी рд╣ोрддा рд╣ै, рдЬो рдХाрдлी рд╣рдж рддрдХ Counter рдЬैрд╕ा рд▓рдЧрддा рд╣ै — рд▓ेрдХिрди рджोрдиों рдоें рдмрдб़ा рдлрд░्рдХ рд╣ै।

Featurelist.count()Counter
рдХ्рдпा рдЧिрдирддा рд╣ैрд╕िрд░्рдл рдПрдХ рджी рдЧрдИ valueрд╕ाрд░े elements рдПрдХ рд╕ाрде
Import рдЪाрд╣िрдП?рдирд╣ीं, built-in рд╣ैрд╣ाँ, collections рд╕े
Result рдХा TypeрдПрдХ рдЕрдХेрд▓ा numberdictionary рдЬैрд╕ा Counter object
Extra FeaturesрдХोрдИ рдирд╣ींmost_common() рдЬैрд╕े methods
Example — рджोрдиों рдХा Comparison
from collections import Counter numbers = [1, 2, 2, 3, 3, 3] # list.count() — рд╕िрд░्рдл рдПрдХ value рдХे рд▓िрдП print(numbers.count(3)) # Counter — рд╕ाрд░े elements рдХे рд▓िрдП рдПрдХ рд╕ाрде print(Counter(numbers))

Output:

3 Counter({3: 3, 2: 2, 1: 1})

рдЕрдЧрд░ рд╕िрд░्рдл рдПрдХ value рдХा count рдЪाрд╣िрдП, рддो count() рдХाрдлी рд╣ै। рд▓ेрдХिрди рдЕрдЧрд░ рд╕ाрд░ी values рдХी frequency рдПрдХ рд╕ाрде рдЪाрд╣िрдП, рддो Counter рдмेрд╣рддрд░ рдФрд░ рддेрдЬ़ рд╣ै।

Try it Yourself »

Common Beginner Mistakes

❌ рдмिрдиा import рдХिрдП Counter рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा
count = Counter([1, 2, 2]) # NameError
✅ рд╕рд╣ी рддрд░ीрдХा
from collections import Counter count = Counter([1, 2, 2])
❌ most_common() рдХा Result List рдХी рддрд░рд╣ рд╕рдордЭрдиा
result = letter_count.most_common(1) print(result[0]) # рдпрд╣ рдПрдХ tuple рд╣ै: ('r', 2)

most_common() рд╣рдоेрд╢ा tuples рдХी list return рдХрд░рддा рд╣ै — рд╣рд░ tuple рдоें (value, count) рд╣ोрддा рд╣ै, рд╕िрд░्рдл value рдирд╣ीं।

❌ Counter рдФрд░ Normal Dictionary рдХो Confuse рдХрд░рдиा

Counter dictionary рдЬैрд╕ा рджिрдЦрддा рд╣ै рдФрд░ dictionary рдЬैрд╕े operations рднी support рдХрд░рддा рд╣ै, рд▓ेрдХिрди рдЗрд╕рдоें most_common() рдЬैрд╕े extra counting-specific methods рднी рд╣ोрддे рд╣ैं, рдЬो normal dictionary рдоें рдирд╣ीं рд╣ोрддे।

❌ list.count() рдХो рдмाрд░-рдмाрд░ Loop рдоें рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा
for item in set(numbers): print(item, numbers.count(item)) # рдзीрдоा рддрд░ीрдХा

рд╣рд░ unique item рдХे рд▓िрдП рдЕрд▓рдЧ рд╕े count() рдЪрд▓ाрдиा рдзीрдоा рдФрд░ inefficient рд╣ै — рдЗрд╕рдХी рдЬрдЧрд╣ рд╕ीрдзे Counter(numbers) рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा рдмेрд╣рддрд░ рдФрд░ рддेрдЬ़ рд╣ै।

Exercise ?

рдЕрдЧрд░ рдХिрд╕ी value рдХो Counter рдоें access рдХрд░ें рдЬो рдоौрдЬूрдж рд╣ी рдирд╣ीं рд╣ै, рддो рдХ्рдпा рд╣ोрдЧा?

KeyError рдЖрдПрдЧा
0 return рд╣ोрдЧा
None return рд╣ोрдЧा

Coding Challenge рдФрд░ Final Revision

рдЕрдм рдЦुрдж рдЕрдкрдиे Online Python Editor рдоें рдЗрди challenges рдХो solve рдХीрдЬिрдП:

  1. рдЕрдкрдиे рдХिрд╕ी favorite sentence рдХे рд╣рд░ word рдХी frequency Counter рд╕े рдиिрдХाрд▓िрдП।
  2. рдХिрд╕ी number рдХी list рдоें рд╕े рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдиे рд╡ाрд▓ा number most_common(1) рд╕े рдкрддा рдХीрдЬिрдП।
  3. рдХिрд╕ी string рдХे vowels (a, e, i, o, u) рдХी рдЕрд▓рдЧ-рдЕрд▓рдЧ count рдиिрдХाрд▓िрдП।
  4. рдПрдХ feedback survey рдХे responses (рдЬैрд╕े "Good", "Bad", "Average") рдХी list рдмрдиाрдЗрдП рдФрд░ Counter рд╕े рд╣рд░ response рдХी count рдФрд░ рд╕рдмрд╕े common response рдиिрдХाрд▓िрдП।
  5. list.count() рдФрд░ Counter() рджोрдиों рд╕े рдПрдХ рд╣ी list рдкрд░ counting рдХрд░рдХे рдЙрдирдХा output compare рдХीрдЬिрдП।

Quick Revision

ConceptSyntax / Example
Importfrom collections import Counter
Counter рдмрдиाрдиाCounter(list_or_string)
Specific Item рдХा Countcount["item"]
рд╕рдмрд╕े Common Elementsmost_common(n)
Missing ItemError рдирд╣ीं, 0 return рдХрд░рддा рд╣ै

FAQ

Python рдоें Counter рдХ्рдпा рд╣ै?

Counter collections module рдХा рдПрдХ tool рд╣ै рдЬो рдХिрд╕ी iterable рдХे рд╣рд░ element рдХी frequency count рдХрд░рдХे рдПрдХ dictionary рдЬैрд╕ा object return рдХрд░рддा рд╣ै।

Counter рдХो рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиे рд╕े рдкрд╣рд▓े рдХ्рдпा рдЬрд░ूрд░ी рд╣ै?

Counter рдХो collections module рд╕े import рдХрд░рдиा рдЬрд░ूрд░ी рд╣ै — from collections import Counter।

most_common() рдХ्рдпा рдХрд░рддा рд╣ै?

most_common() рд╕рдмрд╕े рдЬ्рдпाрджा рдмाрд░ рдЖрдиे рд╡ाрд▓े elements рдХो рдЙрдирдХे count рдХे рд╕ाрде, рд╕рдмрд╕े рдЬ्рдпाрджा рд╕े рд╕рдмрд╕े рдХрдо рдХ्рд░рдо рдоें, tuples рдХी list рдХी рддрд░рд╣ return рдХрд░рддा рд╣ै।

Counter рдФрд░ list.count() рдоें рдХ्рдпा рдлрд░्рдХ рд╣ै?

list.count() рдПрдХ рд╕рдордп рдоें рд╕िрд░्рдл рдПрдХ value рдХा count рдмрддाрддा рд╣ै, рдЬрдмрдХि Counter рдкूрд░ी list рдпा string рдХे рд╕ाрд░े elements рдХी frequency рдПрдХ рд╕ाрде рдиिрдХाрд▓ рджेрддा рд╣ै, рд╕ाрде рд╣ी most_common() рдЬैрд╕े extra features рднी рджेрддा рд╣ै।

рдЕрдЧрд░ Counter рдоें рдХोрдИ value рдоौрдЬूрдж рди рд╣ो рддो рдХ्рдпा рд╣ोрдЧा?

Normal dictionary рдХी рддрд░рд╣ KeyError рдЖрдиे рдХी рдмрдЬाрдп, Counter рдЙрд╕ missing value рдХे рд▓िрдП 0 return рдХрд░рддा рд╣ै।

Summary

Counter = рдХिрд╕ी рднी list рдпा string рдХे elements рдХी frequency, рдПрдХ рд▓ाрдЗрди рдоें рдиिрдХाрд▓рдиे рд╡ाрд▓ा tool।

рдЗрд╕ article рдоें рдЖрдкрдиे рд╕ीрдЦा рдХि Counter рдХ्рдпा рд╣ै, рдЗрд╕े рдХैрд╕े import рдХрд░рддे рд╣ैं, list рдФрд░ string рджोрдиों рдкрд░ рдЗрд╕े рдХैрд╕े рдЗрд╕्рддेрдоाрд▓ рдХрд░рддे рд╣ैं, most_common() рд╕े рд╕рдмрд╕े common elements рдХैрд╕े рдиिрдХाрд▓рддे рд╣ैं, рдФрд░ Counter рд╡ list.count() рдоें рдХ्рдпा рдлрд░्рдХ рд╣ै।

Voting results рдиिрдХाрд▓рдиे рд╕े рд▓ेрдХрд░ text analysis рддрдХ, Counter counting рд╕े рдЬुрдб़ी рд░ोрдЬ़рдорд░्рд░ा рдХी problems рдХो рдмрд╣ुрдд рддेрдЬ़ рдФрд░ рдЖрд╕ाрди рдмрдиा рджेрддा рд╣ै। рдЕрдм рдКрдкрд░ рджिрдпा рдЧрдпा coding challenge рдЦुрдж рдЕрдкрдиे Online Editor рдоें solve рдХрд░ें।

Related Articles

ЁЯзС‍ЁЯТ╗ Python Coding Lab Python code likho, run karo aur practice karo — directly browser mein.