dict[key] = value
data = dict()
data['key'] = value
student_scores = {'Simon': 45 }
print(student_scores)
# {'Simon': 45}
student_scores['Sara'] = 63
print(student_scores)
# {'Simon': 45, 'Sara': 63}
d = {1:2}
d.update({2: 4})
print(d) # {1: 2, 2: 4}
# This automatically creates a new element where
# Your key = key, The value you want to input = value
dictionary_name[key] = value
key = "somekey"
a.setdefault(key, [])
a[key].append(2)
# empty dictionary
dictionary = {}
# lists
list_1 = [1, 2, 3, 4, 5]
list_2 = ["e", "d", "c", "b", "a"]
# populate a dictionary.
for key, value in zip(list_1, list_2):
dictionary[key] = value
# original
print(f"Original dictionary: {dictionary}")
# Add new item to the dictionary
dictionary[6] = "f"
# Updated dictionary
print(f"updated dictionary: {dictionary}")
diction = {'key':'value'}#Adding a dictionary called diction.
print(diction)
diction['newkey']='newvalue'#Adding the newkey key to diction with its value.
print(diction)
#output: {'key':'value','newkey':'newvalue'}