how to append in dictionary in python code example
Example 1: add new keys to a dictionary python
d = {'key':'value'}
print(d)
d['mynewkey'] = 'mynewvalue'
print(d)
Example 2: how to add an element in dictionary
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)
Example 3: Python dictionary append
d1 = {
"1" : 1,
"2" : 2,
"3" : 3
}
d1["4"] = 4
print(d1)
Example 4: how to add an item to a dictionary in python
a_dictonary = {}
a_dictonary.update({"Key": "Value"})
Example 5: how to append in dictionary in python
d = {'a': 1, 'b': 2}
print(d)
d['a'] = 100
d['c'] = 3
d['d'] = 4
print(d)
Example 6: how to append in dictionary in python
my_dict = {"Name":[],"Address":[],"Age":[]};
my_dict["Name"].append("Guru")
my_dict["Address"].append("Mumbai")
my_dict["Age"].append(30)
print(my_dict)