Day 18 of Problem Solving Series In Python

Day 18 of Problem Solving Series In Python | Geethu Talks

Day 18 of Problem Solving Series

Day 18 of Problem Solving Series

👋 Hi friends! Geethu Talks ki welcome. Chat lo ye word ekkuva sarlu vadaru? Word counter ela panichestundo ee roju chuddam.

🎬 Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.

🧩 Real-life Problem

WhatsApp chat lo words: chai, python, chai, code, python, chai. Prathi word entha sarlu vachindi?

📋 Task: Words list lo prathi word count cheyyandi.
📥 Sample input: chai, python, chai, code, python, chai
📤 Sample output: chai: 3, python: 2, code: 1

📚 Concepts Covered

  • 📖 Dictionary as counter
  • 🔑 New key vs existing key
  • 🔁 .items() tho loop
  • 🧮 Frequency pattern

🧠 Step 1: Logic Build Cheddam

Prathi word ki oka counter kavali. Dictionary perfect:

  1. Empty dictionary tho start
  2. Word dictionary lo undha check
  3. Unte count + 1
  4. Lekapothe count = 1 tho start
{ chai: 3, python: 2, code: 1 }

💡 Analogy: Tally marks laga: prathi word ki oka column, vachinappudalla oka gheera.

💻 Step 2: Python Code

words = ["chai", "python", "chai", "code", "python", "chai"]
count = {}

for w in words:
    if w in count:
        count[w] = count[w] + 1
    else:
        count[w] = 1

for word, c in count.items():
    print(f"{word}: {c}")

✅ Output
chai: 3
python: 2
code: 1

🔍 Line by line


CodeMeaning
count = {}Empty dictionary
if w in countWord mundu vachinda?
count[w] + 1Unte count penchu
count[w] = 1Kotha word ki 1 tho start
count.items()Word and count rendu teesukovadam

⚠️ Common Mistake Alert

❌ Wrong: Prathi saari count[w] = 1 rasthe count overwrite avuthundi

count = {}
for w in ["chai", "python", "chai"]:
    count[w] = 1
print(count)

Result:
{‘chai’: 1, ‘python’: 1}

✅ Right: Word mundu undhaa check chesi, unte + 1, lekapothe 1 set cheyyandi.

💡 Bonus tip: Shortcut: count[w] = count.get(w, 0) + 1. Oke line lo same pani!

📝 Quick Recap

  • ✔️ Dictionary tho frequency count
  • ✔️ Existing key: + 1, kotha key: 1
  • ✔️ .items() tho key and value

🏋️ Practice Problems

🟢 Easy: ‘hello’ lo prathi letter frequency print cheyyandi.
Expected output: h:1 e:1 l:2 o:1


🟡 Medium: Ee list lo most common word entha?
Expected output: chai


🔴 Challenge: Rendu words anagrams ena check cheyyandi (letter frequencies same ayithe anagram).
Input: listen, silent → Output: Anagram


💬 Mee answers comments lo share cheyyandi!

🚀 Next: Day 19 – Palindrome Booking Code

Follow @GeethuTalks and stay tuned! 💛

⬅️ Previous: Day 17 of Problem Solving Series In Python

check out our website for more resources

Day 18 of Problem Solving Series Day 18 of Problem Solving Series Day 18 of Problem Solving Series

1 thought on “Day 18 of Problem Solving Series In Python”

Leave a Comment