how to append to list valueof dict code example

Example 1: python append value to dictionary 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']})

Example 2: python dict append value

default_data = {'item1': 1,
                'item2': 2,
          	    }

default_data.update({'item3': 3})
# or
default_data['item3'] = 3