Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created May 27, 2017 10:19
Show Gist options
  • Save m-x-k/f7a89af237560667da7be32d56ae8c30 to your computer and use it in GitHub Desktop.
Save m-x-k/f7a89af237560667da7be32d56ae8c30 to your computer and use it in GitHub Desktop.
Python (2 and 3) how to merge two dicts
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
def merge_two_dicts_python3():
z = {**x, **y}
print(z) # {'c': 4, 'a': 1, 'b': 3}
def merge_two_dicts_python2():
z = dict(x, **y)
print(z) # {'a': 1, 'c': 4, 'b': 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment