Question: Python Questions: Q4. Dictionary Challenge Write a function called add_dictionary . Given two dictionaries and a key, the function add_dictionary returns a new dictionary, that
Python Questions:
Q4. Dictionary Challenge
Write a function called add_dictionary .
Given two dictionaries and a key, the function add_dictionary returns a new dictionary, that is like dict1 , but has a key-value pair added. The added key is given as a parameter, and the value of that new key is the entire 2nd dictionary, dict2 .
person1 = {'name': 'Homer Simpson', 'role': 'schlub'}
person2 = {'name': 'Mr. Burns', 'role': 'supervisor'}
result = add_dictionary(person1, 'manager', person2)
print(result)
# {'name': 'Homer Simpson', 'role': 'schlub', 'manager': {'name': 'Mr. Burns', rol
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
