append dictionary to list python code example
Example 1: Python dictionary append
d1 = {
"1" : 1,
"2" : 2,
"3" : 3
}
d1["4"] = 4
print(d1)
Example 2: python append to dictionary
dict = {1 : 'one', 2 : 'two'}
print(dict)
dict[3] = 'three'
print(dict)
Example 3: Python dictionary append
testing1={'one':1,'two':2}
''' update() is the method of dict() merges another dict into existing ones '''
''' it replaces the keys of exisiting ones with the the new ones '''
testing1.update({'two':3,'noice':69})
print(testing1) """ {'one':1,'two':3,'noice':69} """
Example 4: python dict append
default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
default_data['item3'] = 3
Example 5: append dictionary python
>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}
Example 6: append to dictionary python
languages = {'#1': "Python", "#2": "Javascript", "#3": "HTML"}
languages.update({"#4": "C#"})
languages['#4'] = 'C#'