Q. Write python code to merge to dictionary?
Answers
Answered by
0
Answer:Using the method update()
By using the method update() in Python, one list can be merged into another. But in this, the second list is merged into the first list and no new list is created. It returns None.
Explanation# Python code to merge dict using update() method
def Merge(dict1, dict2):
return(dict2.update(dict1))
# Driver code
dict1 = {'a': 10, 'b': 8}
dict2 = {'d': 6, 'c': 4}
# This return None
print(Merge(dict1, dict2))
# changes made in dict2
print(dict2):
output:None
{'c': 4, 'a': 10, 'b': 8, 'd': 6}
Similar questions