Adding Dictionary Items Exercise
Question 1 of 5
You're building a user profile system. You have an existing profile and want to add new information without overwriting existing data:
profile = {'name': 'Alice', 'email': 'alice@example.com'}
new_info = {'email': 'newalice@example.com', 'phone': '555-1234', 'city': 'Boston'}Which approach safely adds only new keys?
for key, value in new_info.items():
if key not in profile:
profile[key] = valueprofile = profile + new_info
profile.setdefault(new_info)
profile.update(new_info)