append to a dictionary python code example
Example 1: dictionary in python does not support append operation
dict_append = {"1" : "Python", "2" : "Java"}
dict_append.update({"3":"C++"})
print(dict_append)
Example 2: copy a dictionary python
new_dict = old_dict.copy()
Example 3: add new keys to a dictionary python
d = {'key':'value'}
print(d)
d['mynewkey'] = 'mynewvalue'
print(d)
Example 4: how to add an element in dictionary
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)
Example 5: python dictionary
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2018
Example 6: Python dictionary append
d1 = {
"1" : 1,
"2" : 2,
"3" : 3
}
d1["4"] = 4
print(d1)