How to merge two dictionaries with values from dictionary2 replacing those from dictionary1 in Python

1 Answer

0 votes
dictionary1 = {'a': 1, 'b': 2, 'c': 3}
dictionary2 = {'b': 200, 'c': 300, 'd': 4}

dictionary = dictionary1.copy()
dictionary.update(dictionary2)

print(dictionary)


'''
run:

{'a': 1, 'b': 200, 'c': 300, 'd': 4}

'''

 



answered Oct 31, 2017 by avibootz

Related questions

4 answers 242 views
3 answers 243 views
243 views asked Feb 19, 2019 by avibootz
1 answer 148 views
1 answer 153 views
...