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. · اضغط تشغيل لرؤية المخرجات هنا.