default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
# or
default_data['item3'] = 3
a_dictionary = {"name" : "John", "age" : 20}
a_list = []
dictionary_copy = a_dictionary.copy()
a_list.append(dictionary_copy)
print(a_list)
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}
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
from collections import defaultdict
dates_dict = defaultdict(list)
for key, date in cur:
dates_dict[key].append(date)