Exercise 5: Merge Two Dictionaries by Hand — Possible Solution ==================================================================== defaults = {"theme": "dark", "font_size": 12, "autosave": True} overrides = {"font_size": 14, "language": "en"} merged = {} # First, copy every default in default_keys = list(defaults.keys()) index = 0 while index < len(default_keys): key = default_keys[index] merged[key] = defaults[key] index += 1 # Then apply overrides on top — these win on any shared key override_keys = list(overrides.keys()) index = 0 while index < len(override_keys): key = override_keys[index] merged[key] = overrides[key] index += 1 print(merged) Output: {'theme': 'dark', 'font_size': 14, 'autosave': True, 'language': 'en'} WHY THIS WORKS AS AN ANSWER ------------------------------ A while loop can't walk a dictionary directly the way a for loop can ("for key in some_dict") — it needs something with a length and index access. Converting the keys to a list first, list(defaults.keys()), gives the while loop something concrete to count through. Copying defaults first and overrides second is what makes overrides "win" on font_size: merged["font_size"] gets set to 12 by the first loop, then overwritten to 14 by the second loop, since dictionary assignment always replaces an existing key's value rather than adding a duplicate. Reversing the order of the two loops would make defaults win instead — worth trying deliberately to see the difference.