Most common word · أكثر كلمة تكرارًا
Most common word
Find the favourite word of a piece of text.
Work in three stages. Clean: remove the punctuation with .replace() and make everything lowercase with .lower(). Count: .split() the text into words and count them in a dictionary with counts.get(word, 0) + 1. Choose: walk through the words in their original order and switch to a word only when its count is strictly bigger, so that a tie goes to the earlier word.
أكثر كلمة تكراراً
إيجاد الكلمة المفضلة لنص ما.
اعمل في ثلاث مراحل. تنظيف: إزالة علامات الترقيم باستخدام .replace() وجعل كل شيء بأحرف صغيرة باستخدام .lower(). العد: .split() النص إلى كلمات وعدّها في قاموس باستخدام counts.get(word, 0) + 1. الاختيار: مرر عبر الكلمات بترتيبها الأصلي وانتقل إلى كلمة فقط عندما يكون عددها أكبر تماماً، بحيث تذهب التعادل إلى الكلمة الأولى.
Write most_common_word(text) that returns the word used most often, ignoring upper and lower case and the punctuation marks .,!?. If two words tie, return the one that appears first. · اكتب most_common_word(text) ترجع الكلمة المستخدمة الأكثر تكرارًا، بتجاهل الأحرف الكبيرة والصغيرة وعلامات الترقيم .,!?. إذا تعادلت كلمتان، ارجع الأولى التي ظهرت.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.