Homework: Word-Frequency Report
作业: 词频报告
Read → process → write. Five helpers, one orchestrator. The shape of every batch data job.
The five functions
read_words(in_path)— lowercased word listcount_word_frequencies(words)— dict word→counttop_n_words(freq, n)— sorted [(word, count), …]format_report(top_words)— formatted stringwrite_report(in_path, out_path, n)— orchestrator
End-to-end
Python · runnable
Acceptance criteria
- All 9 tests pass
write_reportcalls at least 3 of the 4 helperstop_n_wordssorts count-desc, then alphabetical-ascformat_reportproduces"word: count\n"per entry