append dictionary item to list code example

Example 1: python dictionary of lists append

# Creating an empty dictionary 
myDict = {} 
  
# Adding list as value 
myDict["key1"] = [1, 2] 
  
# creating a list 
lst = ['Geeks', 'For', 'Geeks'] 
  
# Adding this list as sublist in myDict 
myDict["key1"].append(lst) 

# Print Dictionary
print(myDict)

Example 2: how to add an element in dictionary

thisdict =	{
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict["color"] = "red"
print(thisdict)

Example 3: 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)