Skip to content

Instantly share code, notes, and snippets.

@santinoyanz
Last active Jun 20, 2020
Embed
What would you like to do?
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