Updating Dictionary

Write a Python function to update a dictionary with another dictionary and return the updated dictionary.

Example 1:

Input: {"a": 1, "b": 2}, {"b": 3, "c": 4} 
Output: {"a": 1, "b": 3, "c": 4}

Example 2:

Input: {"x": 10, "y": 20}, {"y": 30, "z": 40} 
Output: {"x": 10, "y": 30, "z": 40}

Use the ‘update’ function to update a dictionary.

def update_dict(dict1, dict2):
dict1.update(dict2)
return dict1

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!