how to add element in dictionary python using append code example
Example 1: how to append to a dictionary in python
d = {'a': 1, 'b': 2}
print(d)
d['a'] = 100 # existing key, so overwrite
d['c'] = 3 # new key, so add
d['d'] = 4
print(d)
Example 2: python dict append value
default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
# or
default_data['item3'] = 3