Skip to content

Letter frequencies

Letter frequencies

Return a dictionary that tells you how many times each character appears in a string. For "aab" that is {"a": 2, "b": 1}.

The handy move is freq.get(ch, 0) — it reads the current count for ch, or 0 if you haven't seen it yet. Add 1 and store it back.

Log in or create account

IGCSE & A-Level