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.
תדירות אותיות
חזר מילון שמספר כמה פעמים כל תווית מופיעה במחרוזת. עבור "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) שמחזירה מילון המקשר כל דמות ב-s למספר הפעמים שבה היא מופיעה.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.