Skip to content

Letter frequencies · ⁨字母频率⁩

English

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.

中文

字母频率

返回一个字典,告诉你字符串中每个字符出现了多少次。对于 "aab",结果是 {"a": 2, "b": 1}。

一个方便的写法是 freq.get(ch, 0) —— 它读取 ch 当前的计数,如果还没见过就返回 0。加上 1 再存回去。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩