Most common word · Từ phổ biến nhất
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.
Từ phổ biến nhất
Tìm từ yêu thích của một đoạn văn bản.
Thực hiện theo ba giai đoạn. Làm sạch: loại bỏ dấu câu bằng .replace() và chuyển toàn bộ về chữ thường bằng .lower(). Đếm: .split() văn bản thành các từ và đếm chúng trong một bảng từ bằng counts.get(word, 0) + 1. Chọn: duyệt qua các từ theo thứ tự ban đầu và chỉ chuyển sang từ mới khi số đếm của nó lớn hơn()(strictly) strictly, để trường hợp ngang điểm thuộc về từ xuất hiện trước đó.
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. · Viết most_common_word(text) trả về từ được sử dụng nhiều nhất, bỏ qua chữ hoa/thường và các dấu chấm câu .,!?. Nếu hai từ có số lượng bằng nhau, trả về từ xuất hiện trước.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.