Dictionaries
Creating Dictionaries
empty = {}
person = {"name": "Jack", "age": 26}
mixed = {1: "apple", "colors": ["red", "green"]}
from_pairs = dict([(1, "a"), (2, "b")])Accessing Values
print(person["name"]) # Jack
print(person.get("age")) # 26
print(person.get("city")) # NoneAdding and Updating
person["age"] = 27
person["city"] = "Downtown"Removing
Common Methods
Dictionary Comprehension
Membership and Iteration
Last updated