Ready to begin
No records have been processed. Start with Next step.
![Abhinav’s five-category row-count profile is [3,8,2,0,1], with total 14.](/images/computational-thinking/week-7/customer-profile.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.
profile = {}
foreach bill in bills {
customer = bill.Customer
if (not isKey(profile,customer)) {
profile[customer] = {}
}
foreach item in bill.Items {
category = broadCategory(item.Category)
if (not isKey(profile[customer],category)) {
profile[customer][category] = 0
}
profile[customer][category] = profile[customer][category] + 1
}
}The lab pre-fills all five category keys with zero for a readable table. The pseudocode above creates only observed category keys. They are equivalent for the displayed profile if missing category counts are treated as zero when forming the five-column vector. Category order is [Apparel, Food, Toiletries, Utilities, Household].
| Customer | Apparel | Food | Toiletries | Utilities | Household | Total rows |
|---|---|---|---|---|---|---|
| Abhinav | 3 | 8 | 2 | 0 | 1 | 14 |
| Advaith | 3 | 4 | 1 | 4 | 0 | 12 |
| Ahmed | 0 | 18 | 1 | 5 | 0 | 24 |
| Akhil | 0 | 2 | 0 | 0 | 0 | 2 |
| Akshaya | 3 | 13 | 4 | 0 | 1 | 21 |
| Aparna | 0 | 1 | 0 | 2 | 1 | 4 |
| George | 0 | 4 | 0 | 0 | 0 | 4 |
| Julia | 0 | 6 | 0 | 0 | 0 | 6 |
| Mohith | 1 | 4 | 0 | 0 | 0 | 5 |
| Neeraja | 0 | 6 | 1 | 0 | 0 | 7 |
| Radha | 0 | 5 | 0 | 0 | 0 | 5 |
| Rajesh | 0 | 2 | 0 | 3 | 0 | 5 |
| Srivatsan | 1 | 12 | 1 | 3 | 4 | 21 |
| Sudeep | 1 | 4 | 0 | 0 | 1 | 6 |
| Suresh | 0 | 5 | 0 | 1 | 1 | 7 |
| Vignesh | 0 | 3 | 6 | 3 | 0 | 12 |
A zero here means no such row was observed in these supplied bills. It does not establish that the customer never buys that category elsewhere. Customer → category and customer → customer tables answer different questions.
In profile[Ahmed][Food], what does each key mean?
Ahmed selects the customer; Food selects the category within that customer’s dictionary.
Can bills be shuffled before this accumulation?
Yes. Each row still contributes to the same customer and category.
Does total(profile[customer]) count rupees?
No. Here it totals observed item rows.