Last active
June 20, 2020 08:28
-
-
Save imshayne/073b152f1c3f768e1cd7e8f3421af477 to your computer and use it in GitHub Desktop.
How to merge two dictionaries in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# delcare two dicts with x and y | |
x = dict(a=1, b=2) | |
y = dict(b=2, c=5) | |
## in python 3.5+ ## | |
z = { **x, **y} # z = {'a': 1, 'b': 2, 'c': 5} | |
## in python 2.x ## | |
z = dict(x, **y) # z = {'a': 1, 'c': 5, 'b': 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment