Created
May 24, 2018 11:45
-
-
Save nara-l/97d3eb363592318e83a3cc2b7f7041e3 to your computer and use it in GitHub Desktop.
Adding 2 dictionaries python 2 and 3
This file contains 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
# Python 3.5 > | |
>>> x = {'a':3, 'b':4, 'c': 7} | |
>>> y = {'a': 6, 'b': 8, 'd': 9} | |
>>> z = {**x, **y} | |
>>> z | |
{'a': 6, 'b': 8, 'c': 7, 'd': 9} | |
# Python 2.x | |
z = dict(x, **y) | |
z>>> | |
{'a': 6, 'c': 7, 'b': 8, 'd': 9} | |
# Python overrides duplicate keys from left to right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment