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 & AP