Ivan Chau
0
Q:

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)
2
# 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
0

New to Communities?

Join the community