Home Chapters Projects About
HomeProjects › Day 40
DAY 40 — 60 DAY PYTHON CHALLENGE

Word Frequency Counter

Python mein Word Frequency Counter banao — Hindi mein step by step

Advertisement

Project kya hai?

Day 40 ka project hai Word Frequency Counter! Yeh project banane se aap Python ke important concepts practice kar payenge. Neeche complete code hai — copy karo aur chalao!

Complete Python Code

python — freq.py
text = input("Text enter karo:\n> ")

# Words clean karo
words = text.lower().split()
freq  = {}
for word in words:
    # Punctuation hatao
    word = word.strip(".,!?;:\"'()-")
    if word:
        freq[word] = freq.get(word, 0) + 1

# Sort by frequency
sorted_freq = sorted(freq.items(), key=lambda x: x[1], reverse=True)

print(f"\n=== Word Frequency Analysis ===")
print(f"Total words  : {len(words)}")
print(f"Unique words : {len(freq)}")

print(f"\nTop 10 words:")
print("-" * 35)
for i, (word, count) in enumerate(sorted_freq[:10], 1):
    bar = "#" * count
    pct = count / len(words) * 100
    print(f"  {i:2}. {word:15} {bar:10} {count} ({pct:.1f}%)")

# Most common
if sorted_freq:
    top = sorted_freq[0]
    print(f"\nSabse zyada aaya: '{top[0]}' ({top[1]} baar)")
OUTPUT
Text: Python is great and Python is easy and Python is fun

=== Word Frequency Analysis ===
Total words  : 10
Unique words : 6

Top 10 words:
-----------------------------------
   1. python          ###       3 (30.0%)
   2. is              ###       3 (30.0%)
   3. and             ##        2 (20.0%)
   4. great           #         1 (10.0%)

Sabse zyada aaya: 'python' (3 baar)

Code kaise kaam karta hai?

dict.get(word, 0) + 1 pattern se frequency count hoti hai. sorted(key=lambda, reverse=True) se descending order milti hai. Percentage se relative frequency pata chalti hai.
Advertisement

📋 Project ka Introduction

Word Frequency Counter Python ka Day 40 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: Word Frequency Counter mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 Word Frequency Counter mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: Word Frequency Counter project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.