Ready to begin
No records have been processed. Start with Next step.

Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.
Ready
No records have been processed. Start with Next step.
Predict the next change. Keep track of which list level, field and position convention the procedure uses.
Result = []
CurrentKey = empty; Count = 0
foreach X in RecordsSortedByKey:
if CurrentKey is not empty AND key(X) != CurrentKey:
Result = Result ++ [[CurrentKey,Count]]
Count = 0
CurrentKey = key(X)
Count = Count + 1
if CurrentKey is not empty:
Result = Result ++ [[CurrentKey,Count]]Sorting gathers equal keys into runs. Keep the current key and a count. On a key change, save the previous group, reset the count and begin the new group. Save the final run after the loop because no following change will trigger it. An empty input produces [].
Actual city counts include Chennai 8, Bengaluru 5, Madurai 5, Trichy 3 and Vellore 3. Singleton cities include Ambur, Nagercoil, Salem and Theni. The procedure works because sorting grouped equal cities; it does not require a geographic ordering.
Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.
Ready
No records have been processed. Start with Next step.
Predict the next change. Keep track of which list level, field and position convention the procedure uses.
The source applies the same idea to item-level [Customer,Shop,Category] triples. Sorting those by customer counts item rows per customer; sorting by shop counts item rows per shop. Our complete 30-record bill-summary lab counts BILLS instead: Srivatsan 4 and Ahmed 4, for example. Bill counts, item-row counts and purchased quantities are different units. Full item counting requires original item rows, not category summaries.
Why save a group after the loop?
The last run has no next key change, so otherwise it would never be emitted.
Does four Srivatsan bill summaries mean four purchased items?
No. Each bill can contain many rows and quantities. The unit here is bills.
What result should the grouping procedure return on []?
[], without inventing a group for an unset key.