- Read the chapter entitled Dictionaries
from section "Dictionary Methods" through section "Aliasing and Copying"
- To retrieve all keys in a dictionary named inventory:
- To retrieve all keys as a list: list(inventory.keys())
- To retrieve keys one at a time: for key in inventory:
- To check if a key named "kiwi" exists: if "kiwi" in inventory:
- To retrieve all values: inventory.values()
- To retrieve a specific value, producing a runtime error if the
key is not present: inventory[key-name]
- To retrieve a specific value, producing NO runtime error if the
key is not present: inventory.get(key-name) or
- Key-Value Pairs
- To retrieve all key-value pairs: inventory.items()
- Aliasing vs. Copying
- An example of an alias: dictionary1 = dictionary2
- The expression dictionary2 is dictionary1 returns True
- An example of a copy: dictionary2 = dictionary1.copy()
- The expression dictionary2 is dictionary1 returns False
- Work Exercise 16
- Work Exercise 19 without looking at the answer.
Feel free to add additional words to translate!