xxxxxxxxxx
hh = {"john":3, "mary":4}
# add a entry
hh["vicky"] = 99
print(hh)
# {'john': 3, 'mary': 4, 'vicky': 99}
xxxxxxxxxx
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)
xxxxxxxxxx
# This automatically creates a new element where
# Your key = key, The value you want to input = value
dictionary_name[key] = value
xxxxxxxxxx
# 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}")