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.
ความถี่ตัวอักษร
return dict ที่บอกว่าคุณมีตัวอักษรใดปรากฏ多少次ในสตริง สำหรับ "aab" นั่นคือ {"a": 2, "b": 1}
ท่าทาง有用的คือ freq.get(ch, 0) — มันอ่านค่าปัจจุบันสำหรับ ch, หรือ 0 หากคุณไม่เคยเห็นมันมาก่อน เพิ่ม 1 และจัดเก็บกลับลงไป
Write char_frequency(s) that returns a dictionary mapping each character in s to the number of times it appears. · เขียน char_frequency(s) ที่กลับค่า dictionary Mapping แต่ละ character ใน s กับจำนวนครั้งที่ปรากฏ
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่