Count the Orders
Python
25 pts
Count the Orders
Here are the drinks ordered at a café in Keren this morning:
drinks = ["tea", "coffee", "tea", "juice", "tea", "coffee"]
Build a dictionary called counts that stores how many times each drink was ordered.
- Start with an empty dictionary.
- Loop over
drinks. If the drink is already a key, add 1 to its value. Otherwise, add it with the value1. - Print
counts.
Expected output:
{'tea': 3, 'coffee': 2, 'juice': 1}
Checklist
- Loop over
drinksand count each drink incounts. - Print
counts.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
