Letter frequencies · Tần suất chữ cái
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.
Tần suất chữ cái
Trả về một bảng từ cho biết mỗi ký tự xuất hiện bao nhiêu lần trong một chuỗi. Đối với "aab" đó là {"a": 2, "b": 1}.
Thao tác tiện lợi là freq.get(ch, 0) — nó đọc số lần đếm hiện tại cho ch, hoặc 0 nếu bạn chưa thấy nó. Cộng 1 và lưu lại.
Write char_frequency(s) that returns a dictionary mapping each character in s to the number of times it appears. · Viết char_frequency(s) trả về từ điển ánh xạ mỗi ký tự trong s với số lần xuất hiện của nó.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.