0PricingLogin
Competitive Programming Academy · Lesson

Count Letters with a Frequency Table

Tally characters using a dict or array.

Why Count Characters

Tons of string problems boil down to one question: how often does each character appear? A frequency table answers that in one pass. 📊

The Dictionary Way

A plain dict maps each character to its count. It works for any alphabet, including unicode and symbols.

freq = {}
for ch in 'apple':
    freq[ch] = freq.get(ch, 0) + 1
print(freq)

All lessons in this course

  1. Characters, ord & chr Tricks
  2. Count Letters with a Frequency Table
  3. Palindrome Checks Done Right
  4. Split, Strip & Rejoin Words
← Back to Competitive Programming Academy