python append to dictionary list code example
Example 1: Python dictionary append
# to add key-value pairs to a dictionary:
d1 = {
"1" : 1,
"2" : 2,
"3" : 3
} # Define the dictionary
d1["4"] = 4 # Add key-value pair "4" is key and 4 is value
print(d1) # will return updated dictionary
Example 2: python append to dictionary
dict = {1 : 'one', 2 : 'two'}
# Print out the dict
print(dict)
# Add something to it
dict[3] = 'three'
# Print it out to see it has changed
print(dict)