default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
# or
default_data['item3'] = 3
import collections
a_dict = collections.defaultdict(list) # a dictionary key --> list (of any stuff)
a_dict["a"].append("hello")
print(a_dict)
>>> defaultdict(<class 'list'>, {'a': ['hello']})
a_dict["a"].append("kite")
print(a_dict)
>>> defaultdict(<class 'list'>, {'a': ['hello', 'kite']})
>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}
d = {1:2}
d.update({2: 4})
print(d) # {1: 2, 2: 4}
dict = {1 : 'one', 2 : 'two'}
# Print out the dict
print(dict)
# Add something to it
dict[3] = 'three'
# Print it out to see it has changed
print(dict)
test={'item1': 1,
'item2': 2,
}
default_data = test
default_data.update({'item3': 3})
# or
default_data['item3'] = 3
# This automatically creates a new element where
# Your key = key, The value you want to input = value
dictionary_name[key] = value