Skip to content

Instantly share code, notes, and snippets.

@nara-l
Created May 24, 2018 11:45
Show Gist options
  • Save nara-l/97d3eb363592318e83a3cc2b7f7041e3 to your computer and use it in GitHub Desktop.
Save nara-l/97d3eb363592318e83a3cc2b7f7041e3 to your computer and use it in GitHub Desktop.
Adding 2 dictionaries python 2 and 3
# 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