Letter frequencies · Частотность букв
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Эта страница требует современного браузера (с поддержкой SharedArrayBuffer). Пожалуйста, обновите Chrome, Edge, Firefox или Safari до последней версии.
This one builds on a lesson you haven't finished yet. Do that lesson first: · Это задание опирается на урок, который вы ещё не закончили. Сначала пройдите этот урок:
Python Basics · Основы Python · Dictionaries (records) · Словари (записи) →
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.
Write char_frequency(s) that returns a dictionary mapping each character in s to the number of times it appears. · Напишите char_frequency(s), которая возвращает словарь, сопоставляющий каждый символ из s с количеством его появлений.
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.