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. · לחץ על הרץ כדי לראות את התוצא כאן.