W WolfCode · CSC 141

Homework: Text Statistics

作业: 文本统计

≈ 45 min · python-strings python-functions python-lists · Open in WolfCode

Six functions — five tiny helpers and one assembler. The shape of every text-processing pipeline.

The six functions

  • char_count(text) — non-whitespace chars
  • word_count(text) — whitespace-split words
  • longest_word(words) — first on ties
  • unique_word_count(words) — distinct (use len(set(words)))
  • starts_with_count(words, prefix) — filter comprehension
  • text_stats(text) — assembles dict, calls the helpers

The orchestrator

Python · runnable

One-line idioms used in the helpers

Python · runnable

Acceptance criteria

  • All 10 tests pass
  • text_stats calls at least 3 of the 4 helpers
  • All helpers handle empty input