xxxxxxxxxx
diction[element] = value
# if element not in diction, create new element
xxxxxxxxxx
d = {1: "one", 2: "three"}
d1 = {2: "two"}
# updates the value of key 2
d.update(d1)
d1 = {3: "three"}
# adds element with key 3
d.update(d1)
# {1: 'one', 2: 'two', 3: 'three'}
xxxxxxxxxx
a_dict = {"a": 1, "B": 2, "C": 3}
new_key = "A"
old_key = "a"
a_dict[new_key] = a_dict.pop(old_key)
print(a_dict)
# OUTPUT
{'B': 2, 'C': 3, 'A': 1}
xxxxxxxxxx
d = {1: "one", 2: "three"}
d1 = {2: "two"}
# updates the value of key 2
d.update(d1)
#Output
{1: 'one', 2: 'two'}
xxxxxxxxxx
dict1 = {'color': 'blue', 'shape': 'circle'}
dict2 = {'color': 'red', 'number': 42}
dict1.update(dict2)
# dict1 is now {'color': 'red', 'shape': 'circle', 'number': 42}
xxxxxxxxxx
for project in projects:
project['complete'] = project['id'] in (complete['id'] for complete in completes)
xxxxxxxxxx
d = {1: "one", 2: "three"}
d1 = {2: "two"}
# updates the value of key 2
d.update(d1)
print(d)
d1 = {3: "three"}
# adds element with key 3
d.update(d1)
print(d)