python beginner 2026-11-17 结束

Word frequency report

Write top_words(text, k) that returns the k most common words as a list of (word, count) tuples.

  • Words are compared case-insensitively and returned in lowercase.
  • Ignore punctuation: "Hello, hello!" counts hello twice.
  • Sort by count (highest first); break ties alphabetically.

Acceptance criteria

  • Handles an empty string (returns []).
  • The tests at the bottom print All tests passed.

Hint: re.findall(r"[a-z']+", text.lower()) and collections.Counter.

目前已有 0 人解出。

python
编辑器Ctrl + Enter

            
        

当测试输出 "All tests passed" 时,此挑战会在本浏览器中标记为已解决。

提交您的解决方案进行审核