W WolfCode · CSC 141

Homework: Word-Frequency Report

作业: 词频报告

≈ 45 min · python-file-io python-strings python-lists · Open in WolfCode

Read → process → write. Five helpers, one orchestrator. The shape of every batch data job.

The five functions

  • read_words(in_path) — lowercased word list
  • count_word_frequencies(words) — dict word→count
  • top_n_words(freq, n) — sorted [(word, count), …]
  • format_report(top_words) — formatted string
  • write_report(in_path, out_path, n) — orchestrator

End-to-end

Python · runnable

Acceptance criteria

  • All 9 tests pass
  • write_report calls at least 3 of the 4 helpers
  • top_n_words sorts count-desc, then alphabetical-asc
  • format_report produces "word: count\n" per entry