how to append list in dictionary python code example
Example 1: python dictionary of lists append
myDict = {}
myDict["key1"] = [1, 2]
lst = ['Geeks', 'For', 'Geeks']
myDict["key1"].append(lst)
print(myDict)
Example 2: python append value to dictionary list
import collections
a_dict = collections.defaultdict(list)
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']})