The Standard Library Exists · practice
Order Output on Purpose
The three library-backed
first = [walk_record, read_record]
second = [read_record, walk_record]
A report that follows encounter order changes when the records are rearranged. That makes tests, comparisons, and later saved data needlessly noisy.
Sort a separate list
Build a .sort() .sort() rearranges the list itself into natural order:
The part that catches people is what .sort() hands back:
The sorted list is names. The method returns None, so assigning that
Do not try to sort the Counter in place. Build a separate name list, sort it, then format name=count pieces in that order. Counting and presentation stay as separate jobs.
After names.sort(), where is the alphabetical result?
Test this the direct way: shuffle the records by hand into a different order, call the formatter twice, and confirm both calls return the same line. If the line changes when the input order changes, the sort is not doing its job.
Task
Implement format_category_counts(records) in activity_report.py.
Call
count_categories(records).Build a separate
containing every category key in the Counter. Call
.sort()on that list.Build
name=countpieces in the sorted order.Return the pieces joined by
,.
For an empty record list, return the empty