Introduction
Dictionaries help you store and find data quickly using keys, like a real-life address book.
Jump into concepts and practice - no test required
my_dict = {key1: value1, key2: value2, ...}phone_book = {'Alice': '123-456', 'Bob': '987-654'}word_count = {'hello': 3, 'world': 2}settings = {'volume': 10, 'brightness': 70, 'language': 'English'}fruits = {'apple': 'red', 'banana': 'yellow', 'grape': 'purple'}
# Print the color of banana
print(fruits['banana'])
# Add a new fruit
fruits['orange'] = 'orange'
# Print all fruits and their colors
for fruit, color in fruits.items():
print(f"{fruit} is {color}")dictionary in Python?my_dict?my_dict['key'] = 'value' correctly adds or updates the dictionary.my_dict = {'a': 1, 'b': 2}
my_dict['c'] = 3
print(my_dict)my_dict['c'] = 3 adds a new key 'c' with value 3.my_dict = {'x': 10, 'y': 20}
print(my_dict['z'])my_dict['z'] raises a KeyError.students = [('Alice', 85), ('Bob', 90), ('Alice', 95)]