In the code below, I’m trying to append to a dictionary, I’m still relatively new to Python and couldn’t find a way to do this, after a lot of research.
class my_class:
def __init__(self):
self.key =0
self.my_dict = {}
# self.my_dict.setdefault(0,[])
def add_value_to_dict(self,value):
print(f"Input: {value} Dictionary :{self.my_dict} and key :{self.key}")
self.my_dict[self.key] += [value]
my_class_obj = my_class()
print(my_class_obj.add_value_to_dict("Update 0"))
print(my_class_obj.add_value_to_dict("Update 1"))
print(my_class().my_dict)
print("Objective {0: ['Update 0'],1: ['Update 0']} ")