Skip to content

Instantly share code, notes, and snippets.

@imshayne
Last active June 20, 2020 08:28
Show Gist options
  • Save imshayne/073b152f1c3f768e1cd7e8f3421af477 to your computer and use it in GitHub Desktop.
Save imshayne/073b152f1c3f768e1cd7e8f3421af477 to your computer and use it in GitHub Desktop.
How to merge two dictionaries in python
# 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