how to append values to a key in dictionary python code example
Example 1: how to add an item to a dictionary in python
a_dictonary = {}
a_dictonary.update({"Key": "Value"})
Example 2: dictionary append value python
d = {1:2}
d.update({2: 4})
print(d) # {1: 2, 2: 4}
Example 3: add values to dictionary key python
key = "somekey"
a.setdefault(key, [])
a[key].append(2)
Example 4: python dict append value
default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
# or
default_data['item3'] = 3