Beginner·6 min·basics · dicts
Dictionaries
Dictionaries
A dict maps a key to a value. Keys must be unique and immutable (strings, numbers, tuples).
Three things you'll use constantly
d[key]— read or writed.get(key, default)— read without crashing if missingd.items()— iterate over(key, value)pairs
Try it
- Add three more items to
prices. - Print the total cost of one of each fruit using
sum(prices.values()).