Ready to begin
No records have been processed. Start with Next step.
![Ahmed → [18,20,25,29]. Each ID can be joined to its original bill to recover the shop and item rows.](/images/computational-thinking/week-7/bill-id-join.png)
Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.
Ready
No records have been processed. Start with Next step.
Predict the next key, whether it already exists, and the value that will be stored.
billsByCustomer = {}
billByID = {}
foreach bill in bills {
customer = bill.Customer
if (not isKey(billsByCustomer,customer)) {
billsByCustomer[customer] = []
}
billsByCustomer[customer] = billsByCustomer[customer] ++ [bill.BillNo]
billByID[bill.BillNo] = bill
}
foreach id in billsByCustomer["Ahmed"] {
originalBill = billByID[id]
}A count such as Ahmed→18 cannot tell us which shops supplied the food. Ahmed’s saved IDs are [18,20,25,29] in original bill-number order. IDs are references, not item counts. Use a billByID dictionary to retrieve each record directly rather than rescanning the entire pile for every ID.
All-bill lists include Bill 25, even though it has no Food row. Keep original labels Advaith and Mohith from the cards; the spoken transcripts also use spellings such as Adwaith and Mohit. The examples use the supplied-card labels consistently.
Is length(billsByCustomer[Ahmed]) equal to Ahmed’s Food row count?
No. It is 4 bills; the Food row count is 18.
What information does saving bill IDs preserve?
A way to retrieve original shops, categories and item rows for follow-up questions.
Why not deduplicate identical customer–category rows automatically?
Different bill rows can represent separate purchases. Deduplication changes the unit and loses occurrences.