Week 3

Grocery List

Count repeated items, then show them in order.

You type

Grocery items, one per line, until the person is done.

The tool
Count, then sort Collect items Count repeats Show them in order
What comes out

A sorted list, with a count beside each item.

The question, more slowly

The question is: the person types grocery items until they end input. You print each distinct item once, in alphabetical order, with a count in front. Repeated items increase the count. They do not appear twice.

A dict from item to count is the natural tool. Normalize capitalization so Apple and apple are the same item. When input ends, sort the names and print.

People print the list in the order typed, or they count without merging case. The spec wants the sorted, merged list.

Before you code

Write apple, milk, apple on paper and tally them before you code.