# import itertools class Config: def __init__(self, name, **kwargs): self.name = name self.settings = kwargs # is this the way to store the dict? what happens if there are multiple settings?? def merge(self, new_settings): merged = {**self.settings, **new_settings.settings} return Config("m", **merged) # note down my mistakes for revisiting later def display(self): for i, j in self.settings.items(): print(f"{i}: {j}") @classmethod # did i learn classmethod? i woulld need a recap def from_dict(cls, name, dict: dict): return cls(name, **dict) c1 = Config("defaults", color="blue", size="medium", font="Arial") c2 = Config("custom", size="large", weight="bold") c1.display() # color: blue # size: medium # font: Arial c3 = c1.merge(c2) c3.display() # color: blue # size: large (overwritten by c2) # font: Arial # weight: bold (new from c2) # From dict data = {"theme": "dark", "lang": "en"} c4 = Config.from_dict("prefs", data) c4.display() # theme: dark # lang: en